简体   繁体   English

Microsoft图形和Azure广告用户身份验证

[英]Microsoft graph and Azure Ad user authentication

I have an application registered in Azure ad. 我在Azure广告中注册了一个应用程序。

When i do ADAL with the following details i get a authoriazation token to use with microsoft graph api. 当我使用以下详细信息进行ADAL时,我获得了与微软图形API一起使用的授权令牌。

    `username      = 'admin@domain.com'
    password      = 'password123'
    client_id     = application id from azure ad
    client_secret = keys from application on azure ad
    tenant        = directory id from azure ad`

Using this token i can fetch the list of all sites in my sharepoint account. 使用此令牌,我可以获取我的sharepoint帐户中的所有网站的列表。

Below is the endpoint i call to fetch the sites with the bearer token: https://graph.microsoft.com/v1.0/sites?search=* 下面是我呼叫使用持票人令牌获取站点的端点: https://graph.microsoft.com/v1.0/sites?search=*https://graph.microsoft.com/v1.0/sites?search=*

But when I just do the client authentication using token generated using below endpoint Iam not able to access the sites list. 但是当我只使用使用下面的端点生成的令牌进行客户端身份验证时,Iam无法访问站点列表。 login.microsoftonline.com/tenant_id/oauth2/v2.0/token

    `grant_type : client_credentials
    clientid : client_id
    clientsecrte : client_secret
    scope : https://graph.microsoft.com`

It does not return all of the sites. 它不会返回所有网站。

Is there a way of getting all sites list with just client authentication. 有没有办法通过客户端身份验证获取所有网站列表。

Or can i get a token for user authentication without user password. 或者我可以获得用户身份验证令牌而无需用户密码。

Here is the token decoded that i am using: { "aud": "https://graph.microsoft.com", "iss": "https://sts.windows.net/586145ec-0428-4da6-8061-fb114257ab70/", "iat": 1528949458, "nbf": 1528949458, "exp": 1528953358, "aio": "Y2dgYLh*************xAAA=", "app_displayname": "App Name", "appid": "504ddb16-2899-48be-be57-**********", "appidacr": "1", "idp": "https://sts.windows.net/586145ec-0428-4da6-8061-fb114257ab70/", "oid": "afcf166f-24c2-49f1-b285-b672d0413c50", "roles": [ "Sites.Read.All", "Sites.ReadWrite.All", "Sites.Manage.All", "Sites.FullControl.All", ], "sub": "afcf166f-24c2-49f1-b285-b672d0413c50", "tid": "586145ec-0428-4da6-8061-fb114257ab70", "uti": "hwYd8FZCH0KruWGRFiIHAA", "ver": "1.0" } 以下是我正在使用的令牌解码: { "aud": "https://graph.microsoft.com", "iss": "https://sts.windows.net/586145ec-0428-4da6-8061-fb114257ab70/", "iat": 1528949458, "nbf": 1528949458, "exp": 1528953358, "aio": "Y2dgYLh*************xAAA=", "app_displayname": "App Name", "appid": "504ddb16-2899-48be-be57-**********", "appidacr": "1", "idp": "https://sts.windows.net/586145ec-0428-4da6-8061-fb114257ab70/", "oid": "afcf166f-24c2-49f1-b285-b672d0413c50", "roles": [ "Sites.Read.All", "Sites.ReadWrite.All", "Sites.Manage.All", "Sites.FullControl.All", ], "sub": "afcf166f-24c2-49f1-b285-b672d0413c50", "tid": "586145ec-0428-4da6-8061-fb114257ab70", "uti": "hwYd8FZCH0KruWGRFiIHAA", "ver": "1.0" }

I get other permissions also but these are site related in Microsoft Graph api 我也获得了其他权限,但这些是Microsoft Graph api中的站点相关

Cause: 原因:

The successful one is using ROPC flow and it can get delegated permissions onbehlaf of the user. 成功的一个是使用ROPC flow ,它可以获得用户的授权权限 But the failed one is using client_credentials flow which get application permissions and cannot onbehlf of the user. 但失败的一个是使用client_credentials flow来获取应用程序权限 ,并且不能用户使用。


Updated Answer 更新的答案

Solution:(Before you do this test, ensure you have SPO license in your tenant) 解决方案:(在您进行此测试之前,请确保您的租户拥有SPO许可证)

  1. Try to add Sites.Read.All Application permission in your registrated AAD Application and do admin consent for it before you getting token. 尝试在注册的AAD应用程序中添加Sites.Read.All应用程序权限,并在获得令牌之前对其进行管理员同意

  2. If you're using AAD v1 endpoint, you can do admin consent by clicking Grant permissions button .If you're using v2 endpoint, please input this kind of URL in your internet browser to do admin grant: 如果您正在使用AAD v1端点,则可以通过单击“授予权限”按钮来执行管理员同意。如果您使用的是v2端点,请在Internet浏览器中输入此类URL以执行管理员授予:

    https://login.microsoftonline.com/{yourtenant}/adminconsent?client_id={the applicationid of your client}&state=123&redirect_uri={the redirect uri of your app}

and sign in with Global admin account and accept this permission. 并使用全局管理员帐户登录并接受此权限。

在此输入图像描述

  1. In my test lab, I used v2 endpoint.Here is the token I got via Postman: 在我的测试实验室中,我使用了v2端点。这是我通过Postman获得的令牌: 在此输入图像描述

Here is decoded token in https://jwt.ms , we can decoded the token to ensure it has the permissions we want. 这是https://jwt.ms中的解码令牌,我们可以解码令牌以确保它具有我们想要的权限。

在此输入图像描述

  1. Then I use this token in the head to call Microsoft Graph API and succeeded: 然后我在脑袋中使用此标记来调用Microsoft Graph API并成功:

在此输入图像描述

For more detials about Site permission for Microsoft Graph, please refer to this documentation . 有关Microsoft Graph的站点权限的更多详细信息,请参阅此文档

Please let me know if this helps! 请让我知道这可不可以帮你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM