[英]How to get the access token from azure using asp.net mvc
We just wanted to get the access token of azure using asp.net MVC web application.我们只是想使用 asp.net MVC web 应用程序获取 azure 的访问令牌。
We have to use the below line of code to get the azure access token.我们必须使用下面的代码行来获取 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
But we are getting a response to the open azure login page.但是我们收到了对打开的 azure 登录页面的响应。 Can you please help me with this.你能帮我解决这个问题吗?
Is there any way to get token from azure using asp.net MVC So please suggest Thanks in advance.有没有办法使用 asp.net MVC 从 azure 获取令牌所以请提前建议谢谢。
It seems that you want to implement the client credentials flow .您似乎想要实现客户端凭据流。
The authority is incorrect.权限不正确。 It should be https://login.microsoftonline.com/{tenantId}
.它应该是https://login.microsoftonline.com/{tenantId}
。
Not sure why you add the C# tag but your code is VB.不知道为什么要添加 C# 标签,但您的代码是 VB。
So here is a C# sample for your reference.所以这里有一个 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.