We need to access Sharepoint (Graph) APIs through our API layer (no web layer here). I am trying to access Graph APIs through by Java based Rest APIs with AAD. I have registered my application in Azure and I have client_id and Secrete.
- grant_type=authorization_code flow
I have tried authorization_code flow https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
Getting code from "/oauth2/v2.0/authorize" and then access_token with that code works fine in web application where we can sign-in and accept consent page in "/oauth2/v2.0/authorize" flow.
But when I am trying to access same through my API its giving below error:
http://localhost:9090/ping?error=login_required&error_description=AADSTS50058: A silent sign-in request was sent but no user is signed in. The cookies used to represent the user's session were not sent in the request to Azure AD. This can happen if the user is using Internet Explorer or Edge, and the web app sending the silent sign-in request is in different IE security zone than the Azure AD endpoint (login.microsoftonline.com).
Timestamp: 2020-08-07 05:32:10Z&error_uri=https://login.microsoftonline.com/error?code=50058
- grant_type=client_credentials
When I generate access_token with grant_type=client_credentials, client_id & client_secrete then its giving below error:
App access token request:
curl -X POST \
https://login.microsoftonline.com/<tennantid>/oauth2/v2.0/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials&client_id=< client_id>&client_secret=<client_secret>&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default'
{
"error": {
"code": "AccessDenied",
"message": "Either scp or roles claim need to be present in the token.",
"innerError": {
"date": "2020-08-07T06:23:21",
"request-id": "***-15e3-437d-8297-****"
}
}
}