Azure ad b2c .NET Core 2.1 Azure AD B2C Web和API
使用Azure ad b2c .NET Core 2.1 Azure AD B2C Web和API,azure-ad-b2c,asp.net-core-2.1,.net-core-2.1,Azure Ad B2c,Asp.net Core 2.1,.net Core 2.1,使用VS 2017 15.7.2+可以轻松创建Azure AD B2C Web或API应用程序 因此,我创建了一个同时具有这两种功能的解决方案,但我正在尝试从Web应用程序获取访问令牌,并使用它调用API,但我找不到方法 我尝试了选项1(不起作用): 我尝试了选项2(无效),MSAL(Microsoft.Identity.Client): 我还尝试修改Azure示例中的代码,例如(Framework 4.5.1)或(Core 2.0和OpenID,无B2C),但失败了 这也提到了在Authori
VS 2017 15.7.2+
可以轻松创建Azure AD B2C Web或API应用程序
因此,我创建了一个同时具有这两种功能的解决方案,但我正在尝试从Web应用程序获取访问令牌,并使用它调用API,但我找不到方法
我尝试了选项1(不起作用):
我尝试了选项2(无效),MSAL(Microsoft.Identity.Client):
我还尝试修改Azure示例中的代码,例如(Framework 4.5.1)或(Core 2.0和OpenID,无B2C),但失败了
这也提到了在AuthorizationCodeReceived上实现,但Core 2.1似乎已经通过AddAzureADB2C
(黑框)实现了这一点。这个新库的文档似乎丢失或正在进行中,因为我找不到它
我想知道,如何使用.NETCore2.1中的内置功能获取访问令牌
我相信,如果我知道如何在AuthorizationCodeReceived上实现,我将离找到答案更近一步。在这里,我创建的代码源和票据与此相关:我有一个类似或相同的问题。样本和文档适用于1.1或2.0,B2C在新的.Net Core 2.1中的设置有所不同。我用邮递员也拿不到代币。你有没有试过邮递员来测试B2C设置:Hi@Jaider。看见
private async Task<string> GetAccessTokenCacheAsync()
{
string authority = $"{AzureAdOptions.Instance}{AzureAdOptions.ClientId}/{AzureAdOptions.SignUpSignInPolicyId}/";
string clientId = AzureAdOptions.ClientId;
Uri redirectUri = new Uri("https://localhost:12345/");
string resource = targetApplicationID;
AuthenticationContext ac = new AuthenticationContext(authority);
AuthenticationResult result = null;
try
{
result = await ac.AcquireTokenSilentAsync(resource, clientId);
}
catch (AdalException adalException)
{
if (adalException.ErrorCode == AdalError.FailedToAcquireTokenSilently
|| adalException.ErrorCode == AdalError.InteractionRequired)
{
result = await ac.AcquireTokenAsync(resource, clientId, redirectUri,
new PlatformParameters()); //PromptBehavior.Auto
}
}
return result.AccessToken;
}
System.NotImplementedException: 'The method or operation is not implemented.'
private async Task<string> GetAccessTokenCacheAsync() {
string authority = $"{AzureAdOptions.Instance}{AzureAdOptions.ClientId}/{AzureAdOptions.SignUpSignInPolicyId}/";
PublicClientApplication myApp = new PublicClientApplication(AzureAdOptions.ClientId, authority);
AuthenticationResult authenticationResult = await myApp.AcquireTokenAsync(
new[] { $"{ApiScopeUrl}/read", $"{ApiScopeUrl}/write" }
,
myApp.Users.FirstOrDefault()
,
UIBehavior.ForceLogin
,null,null
,authority
).ConfigureAwait(false);
return authenticationResult.AccessToken;
}
System.NotImplementedException: 'The method or operation is not implemented.'