JWT CSOM/REST Azure Active Directory

Andrew

We have been trying to make requests to sharepoint using CSOM/REST Authentication Bearer header requests with a token. It is related to this question below:

C# CSOM Sharepoint Bearer request from azure active directory

There is only one link/example that works all others including the android ADAL approach don't work.

https://samlman.wordpress.com/2015/02/27/using-adal-access-tokens-with-o365-rest-apis-and-csom/

They don't seem to return as long a token, when we look at the token in JWT parser, we can see that the scp value is different, the one that fails has user_impersonate, but the working one has AllSites.Manage AllSites.Read AllSites.Write MyFiles.Read MyFiles.Write. The aud url is also different, are one or both of these the problem and how do I get it working?

This is the ones that fails:

{
  "aud": "https://srmukdev.onmicrosoft.com/3Squared-Api-Test",
  "iss": "...",
  "iat": ...,
  "nbf": ...,
  "exp": ..,
  "acr": "...",
  "aio": "...",
  "amr": [
    "pwd",
    "mfa"
  ],
  "appid": "...",
  "appidacr": "0",
  "e_exp": ...,
  "family_name": "...",
  "given_name": "...",
  "ipaddr": "...",
  "name": "...",
  "oid": "...",
  "onprem_sid": "...",
  "platf": "3",
  "scp": "user_impersonation",
  "sub": "...",
  "tid": "...",
  "unique_name": "...",
  "upn": "...",
  "ver": "1.0"
}

This is the ones that works:

{
  "aud": "https://srmukdev.sharepoint.com/",
  "iss": "...",
  "iat": ...,
  "nbf": ...,
  "exp": ...,
  "acr": "...",
  "aio": "...",
  "amr": [
    "pwd",
    "mfa"
  ],
  "app_displayname": "...",
  "appid": "...",
  "appidacr": "0",
  "e_exp": ...,
  "family_name": "...",
  "given_name": "...",
  "ipaddr": "...",
  "name": "...",
  "oid": "...",
  "onprem_sid": "...",
  "platf": "3",
  "puid": "...",
  "scp": "AllSites.Manage AllSites.Read AllSites.Write MyFiles.Read MyFiles.Write",
  "sub": "...",
  "tid": "...",
  "unique_name": "...",
  "upn": "...",
  "ver": "1.0"
}
Fei Xue - MSFT

The access token is for the specific resource by checking its aud claim. The first token is used for authentication for your custom resource.

To get the token for the specific resource, we can use the parameter resource to specify which resource we want to request for the token. For example, if I want to get the token for the Microsoft Graph resource, we can construct the request like below:

POST /{tenant}/oauth2/token HTTP/1.1
Host: https://login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&client_id=2d4d11a2-f814-46a7-890a-274a72a7309e
&code=AwABAAAAvPM1KaPlrEqdFSBzjqfTGBCmLdgfSTLEMPGYuNHSUYBrqqf_ZT_p5uEAEJJ_nZ3UmphWygRNy2C3jJ239gV_DBnZ2syeg95Ki-374WHUP-i3yIhv5i-7KU2CEoPXwURQp6IVYMw-DjAOzn7C3JCu5wpngXmbZKtJdWmiBzHpcO2aICJPu1KvJrDLDP20chJBXzVYJtkfjviLNNW7l7Y3ydcHDsBRKZc3GuMQanmcghXPyoDg41g8XbwPudVh7uCmUponBQpIhbuffFP_tbV8SNzsPoFz9CLpBCZagJVXeqWoYMPe2dSsPiLO9Alf_YIe5zpi-zY4C3aLw5g9at35eZTfNd0gBRpR5ojkMIcZZ6IgAA
&redirect_uri=https%3A%2F%2Flocalhost%2Fmyapp%2F
&resource=https%3A%2F%2Fservice.contoso.com%2F
&client_secret=p@ssw0rd

If you want to acquire the access token for https://srmukdev.sharepoint.com/, you need to assign the value of resource parameter with https://srmukdev.sharepoint.com/ in the request according to the flow you were using.

More detail about the flows Azure AD support to acquire access token, you can refer the link below:

Azure Active Directory Authentication Protocols

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Verifying JWT from Azure Active Directory

From Dev

ActiveDirectoryMembershipProvider with Azure Active Directory

From Dev

Azure Active Directory and OWIN

From Dev

Azure Active Directory Roles

From Dev

Using JWT with Active Directory authentication in NodeJS backend

From Dev

Who is the owner of an Azure active directory?

From Dev

Azure Active Directory Connection String

From Dev

Azure Active Directory and Windows Authentication

From Dev

Authentication of a WebAPI with Azure Active Directory

From Dev

New azure active directory with powershell

From Dev

Azure Active Directory and WCF authentication

From Dev

How to access Azure Active Directory?

From Dev

Migration to and from Azure Active directory

From Dev

Cannot delete Azure Active Directory

From Dev

Simple Directory Lookup in Azure Active Directory

From Dev

AD Directory Programming with Azure Active Directory

From Dev

Simple Directory Lookup in Azure Active Directory

From Dev

Can I use Azure Active Directory For Testing

From Dev

Azure Active Directory Daemon Client Using Certificates

From Dev

Azure Active Directory Application Key Renewal

From Dev

Windows Azure Active Directory - expiration of refreshtoken

From Java

Azure Active Directory Safari Redirection Issue

From Dev

How to remove Azure Active Directory from Subscription

From Dev

Check if username exist in Microsoft Azure Active Directory

From Dev

Logging into Azure Active Directory without a Domain Name

From Dev

In Azure Active directory user disable option is there?

From Dev

Using OAuth to connect to a Windows Azure Active Directory

From Dev

Transforming claims with Windows Azure Active Directory (WAAD)

From Dev

Verify a domain name in Azure Active Directory

Related Related

  1. 1

    Verifying JWT from Azure Active Directory

  2. 2

    ActiveDirectoryMembershipProvider with Azure Active Directory

  3. 3

    Azure Active Directory and OWIN

  4. 4

    Azure Active Directory Roles

  5. 5

    Using JWT with Active Directory authentication in NodeJS backend

  6. 6

    Who is the owner of an Azure active directory?

  7. 7

    Azure Active Directory Connection String

  8. 8

    Azure Active Directory and Windows Authentication

  9. 9

    Authentication of a WebAPI with Azure Active Directory

  10. 10

    New azure active directory with powershell

  11. 11

    Azure Active Directory and WCF authentication

  12. 12

    How to access Azure Active Directory?

  13. 13

    Migration to and from Azure Active directory

  14. 14

    Cannot delete Azure Active Directory

  15. 15

    Simple Directory Lookup in Azure Active Directory

  16. 16

    AD Directory Programming with Azure Active Directory

  17. 17

    Simple Directory Lookup in Azure Active Directory

  18. 18

    Can I use Azure Active Directory For Testing

  19. 19

    Azure Active Directory Daemon Client Using Certificates

  20. 20

    Azure Active Directory Application Key Renewal

  21. 21

    Windows Azure Active Directory - expiration of refreshtoken

  22. 22

    Azure Active Directory Safari Redirection Issue

  23. 23

    How to remove Azure Active Directory from Subscription

  24. 24

    Check if username exist in Microsoft Azure Active Directory

  25. 25

    Logging into Azure Active Directory without a Domain Name

  26. 26

    In Azure Active directory user disable option is there?

  27. 27

    Using OAuth to connect to a Windows Azure Active Directory

  28. 28

    Transforming claims with Windows Azure Active Directory (WAAD)

  29. 29

    Verify a domain name in Azure Active Directory

HotTag

Archive