Нам нужно получить доступ к API Sharepoint (Graph) через наш уровень API (здесь нет веб-слоя). Я пытаюсь получить доступ к API-интерфейсам Graph с помощью API-интерфейсов Rest на основе Java с помощью AAD. Я зарегистрировал свое приложение в Azure, и у меня есть client_id и Secrete.
- grant_type = authorization_code flow
Я пробовал поток authorization_code https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
Получение кода от "/oauth2/v2.0/authorize", а затем access_token с этим кодом отлично работает в веб-приложении, где мы можем войти и принять страницу согласия в потоке "/oauth2/v2.0/authorize".
Но когда я пытаюсь получить доступ к нему через свой API, он выдает ошибку ниже :
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
Когда я генерирую access_token с grant_type = client_credentials, client_id и client_secrete, то выдает ошибку ниже:
Запрос токена доступа к приложению:
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-****"
}
}
}
Я добавил в свое приложение следующие разрешения: введите описание изображения здесь