简体   繁体   English

如何使用 asp.net mvc 从 azure 获取访问令牌

[英]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.

相关问题 在 Azure 集成 ASP.NET 核心 MVC 应用程序中获取访问令牌 - Get the access token in an Azure integrated ASP.NET Core MVC application 使用 WebClient 或类似方法从 .NET 框架 2.0 ASP.NET 应用程序获取 Azure AD 访问令牌 - Get Azure AD Access Token from a .NET framework 2.0 ASP.NET app using WebClient or similar method 在ASP.NET WebForms中将OAuth与令牌一起使用Azure身份验证不是MVC - Azure Authentication using OAuth with token in ASP.NET WebForms NOT MVC 如何从 gmail 中的刷新令牌获取访问令牌 asp.net 中的 api - How to get access token from refresh token in gmail api in asp.net 使用CCW的ASP.NET MVC3 AntiForgery令牌 - Using ASP.NET MVC3 AntiForgery token from CCW 如何使用Azure AD和asp.net MVC保护控制器访问 - How to secure controller access using Azure AD and asp.net MVC 如何在 ASP.NET API 中获取传入的访问令牌 - How to get the incoming access token in ASP.NET API 如何开始使用 ASP.Net MVC 4 / Azure 和 MonoDevelop? - How to get started with ASP.Net MVC 4 / Azure and MonoDevelop? Asp.net Web Api 2 - 如何从C#代码获取access_token - Asp.net Web Api 2 - how to get access_token from C# code ASP.NET Web API 和 OpenID Connect:如何从授权码获取访问令牌 - ASP.NET Web API and OpenID Connect: how to get Access Token from Authorization Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM