![](/img/trans.png)
[英]Get the access token in an Azure integrated ASP.NET Core MVC application
[英]How to get the access token from azure using asp.net mvc
我们只是想使用 asp.net MVC web 应用程序获取 azure 的访问令牌。
我们必须使用下面的代码行来获取 azure 访问令牌。
Dim authorityUri As String = "https://login.microsoftonline.com/common/oauth2/authorize"
Dim authContext As AuthenticationContext = New AuthenticationContext(authorityUri)
Dim TokenTask = Await authContext.AcquireTokenAsync(resource, ClientCredetial)
Dim getToken = TokenTask.AccessToken()
Return getToken
但是我们收到了对打开的 azure 登录页面的响应。 你能帮我解决这个问题吗?
有没有办法使用 asp.net MVC 从 azure 获取令牌所以请提前建议谢谢。
您似乎想要实现客户端凭据流。
权限不正确。 它应该是https://login.microsoftonline.com/{tenantId}
。
不知道为什么要添加 C# 标签,但您的代码是 VB。
所以这里有一个 C# 样品供您参考。
string authority = "https://login.microsoftonline.com/{tenantId}";
string clientId = "{clientId}";
string secret = "{secret}";
string resource = "{resource}";
var credential = new ClientCredential(clientId, secret);
AuthenticationContext authContext = new AuthenticationContext(authority);
var token = authContext.AcquireTokenAsync(resource, credential).Result.AccessToken;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.