Azure: Azure AD的使用

简介

注册一个Web应用程序

1. 概述:显示应用程序的app Id

2. 身份验证:显示了重定的URL

3.证书和密码: 生成一个client secret,  以便你可以使用client credential和authrization code的方式获取token4.API 权限: 给当前的应用程序赋予权限,如下图,当前APP 有访问Mircrosoft Graph(它让用户可以使用API的方式调用Azure Active Directory, Office 365 services, Enterprise Mobility and Security services, Windows 10 services, Dynamics 365, and more的内容,比如:邮件,你的身份信息,联系方式 ,Calendar等)中读用户的profile的权限, 以及有另一个应用test-api的读和写权限。

 

隐含模式,一定要启用上面的访问令牌和ID令牌,否则就会报如下错误 

获取token(使用Postman)

  • Callback URL:http://localhost:8087, 如果你请求的URL与重定的URL不匹配,就会报错“The reply url specified in the request does not match the reply urls configured for the application: '00a594da-0a72-483e-9640-2337f97c62fb'.”
  • AuthUrl: https://login.chinacloudapi.cn/272c1cac-a352-405d-9656-c5c8b0c58aa1/oauth2/authorize?resource=https%3a%2f%2fmicrosoftgraph.chinacloudapi.cn%2f
  • tanent Id: 272c1cac-a352-405d-9656-c5c8b0c58aa1
  • client Id: 00a594da-0a72-483e-9640-2337f97c62fb
  • client Secret: XReQkZq8:]cJ[dgdbf/zcFkx0Omcjj59

使用Token得到microsoft graph(国内版)中当前用户的基本信息

对access token中的payload进行base解码,结果如下:

{"aud":"https://microsoftgraph.chinacloudapi.cn/","iss":"https://sts.chinacloudapi.cn/7f7981b1-c872-48c3-9eaf-fa20edf4dbb6/","iat":1562920793,"nbf":1562920793,"exp":1562924693,"acr":"1","aio":"ATQAy/8DAAAAy3uyCtEeqMssrhswVWFlXh0u89k9/qg5yATzR3CeoRyiKpifpcHCke0NXKGXj6bm","altsecid":"5::2003BFFD816B822B","amr":["pwd"],"app_displayname":"testapp","appid":"c3405752-9f09-4f5a-aac6-de274efd47ab","appidacr":"0","email":"[email protected]","family_name":"Cong","given_name":"[email protected]","idp":"https://sts.chinacloudapi.cn/a09fa999-f876-4f4f-88dd-8a1983c066da/","ipaddr":"116.238.237.102","name":"[email protected] Cong","oid":"f189ebc8-433e-42a8-83c1-fcffe7635b41","platf":"3","puid":"10033230C522D070","scp":"User.Read","sub":"xv6Ll1gZioWeEyYT5YCZ_joF7wzzDXORayOK_4K6x6U","tid":"7f7981b1-c872-48c3-9eaf-fa20edf4dbb6","unique_name":"[email protected]","uti":"0KjQKZJHSEewWOef6k0LAA","ver":"1.0","xms_tcdt":1562917476} 

可以看出aud(audience) 是https://microsoftgraph.chinacloudapi.cn/,也就是说这个token只对当前graph(https://microsoftgraph.chinacloudapi.cn/) 开头的API有效。

发布了105 篇原创文章 · 获赞 46 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/wucong60/article/details/92804144