且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有一种方法可以通过JWT和Azure AD令牌授权Net Core 3.0 API

更新时间:2023-02-15 08:46:30

您当前已注册Azure应用程序,可以将其设置为客户端应用程序,然后需要创建代表api的后端应用程序,然后让用户登录到您的客户端应用程序以完成授权并获取访问令牌,最后使用该访问令牌调用api应用程序.

You have currently registered an Azure application, you can set it as a client application, and then you need to create a back-end application representing the api, and then let the user log in to your client application to complete authorization and obtain an access token, and finally use the the access token calls the api application.

操作过程如下:

首先公开后端应用程序的api,然后添加客户端应用程序.

First expose the api of the back-end application and add the client application.

接下来,在"API权限"下,授予您的前端应用程序对您的后端api的访问权限:

Next,under 'API permissions', give your front-end application access to your backend api:

  • 在"API权限"下,单击添加权限",然后单击我的API"标签.
  • 找到您的后端应用程序,然后选择适当的范围.
  • 点击添加权限".
  • 获得您的API的管理员同意.

接下来,您需要使用

Next, you need to use the auth code flow to obtain an access token,which requires you to log in to the user and obtain the authorization code, and then use the authorization code to redeem the access token.

解析令牌:

最后,您可以使用令牌来调用api.

Finally, you can use the token to call the api.

完整的 查看全文