[英]Azure Auth Service not work after publishing
我有一个.net Web API,其中提供了SPA的终结点以获取Azure oAuth 2访问令牌。 当我在本地运行Web API时,该服务运行正常。 但是,当我将服务发布到MS Azure时,终结点向我返回{“ Message”:“发生错误。”}。 仅当我要验证用户身份时才引发错误。 如果我为具有客户端机密的客户端身份验证运行相同的代码,则将正确返回访问令牌。
我的问题是,为什么这只会在天蓝色时发生,我该如何解决?
用户身份验证 (不适用于Azure)
该资源例如:“ https://graph.microsoft.com ”
public string Get([FromUri] String resource)
{
var token = GetAuthenticatedUserAsync(resource).Result;
return token.AccessToken;
}
//Authentication of an user
[DisableCors()]
private static async Task<Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult> GetAuthenticatedUserAsync(String resource)
{
AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/{tenant}/oauth2/authorize");
return await authContext.AcquireTokenAsync(resource, ConfigurationManager.AppSettings["UserClientId"], new Uri("{redirect url}"), new PlatformParameters(PromptBehavior.Auto)).ConfigureAwait(false);
}
客户端身份验证 (在Azure上运行)
//Authentication of a client
[DisableCors()]
public static async Task<Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult> GetAuthenticatedAppAsync()
{
AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/{tenant}/oauth2/authorize");
var credentials = new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(ConfigurationManager.AppSettings["AppClientId"], ConfigurationManager.AppSettings["AppClientSecret"]);
return await authContext.AcquireTokenAsync(ConfigurationManager.AppSettings["GraphResource"], credentials).ConfigureAwait(false);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.