当前位置: 首页 > 知识库问答 >
问题:

无法从基于Java的Rest API访问SharePoint图形API

乜飞航
2023-03-14

我们需要通过我们的API层(这里没有Web层)访问Sharepoint(图形)API。我正在尝试通过基于AAD的JavaRest API访问图形API。我已经在Azure中注册了我的应用程序,并且client_id和Secrete。

  1. grant_type=authorization_code流量

我尝试过authorization_code流https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow

获取代码从"/o的2/v2.0/授权",然后与该代码access_token工作正常的Web应用程序中,我们可以登录和接受同意页面"/o的2/v2.0/授权"流。

但是当我试图通过我的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时,client_id

应用程序访问令牌请求:

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-****"
        }
    }
}

共有1个答案

俞子实
2023-03-14

正如Allen Wu几分钟前所评论的,假设您希望您的Java后端访问用户的Sharepoint文件(看起来这就是您想要的),您基本上不能将“client_credentials”用于此目的。OAuth的概念是使用代表用户生成的令牌,并在Azure中连接/注册的服务中转发/使用它。

您必须做的是坚持您测试的“authorization_code”流,并将您获得的令牌(在您的用户可以看到的某些前端,无论这是什么)转发到您的Java服务/API(在REST客户端中,您将HTTP请求附加给它)。

在Java服务/API中,您提取令牌并将其转发到图形应用编程接口。微软也提供了在使用/转发令牌之前验证令牌的方法。最佳做法是在执行任何其他操作之前,在安全拦截器中对Java服务进行验证。

 类似资料:
  • 使用Microsoft graph api,尤其是SharePoint beta API,我经常遇到问题。我知道它的测试版,但仍然; 因此,当我尝试使用graph explorer中的Graph API访问sharepoint列表时,问题是:GET https://Graph . Microsoft . com/beta/sites/{ site-id }/lists/{ list-id } 所以

  • 有趣的是,当我使用https://developer.microsoft.com/en-us/graph/graph-explorer时,我可以获得用户的电子邮件。我已经检查了查询,但似乎没有任何区别。我看到的唯一区别是,在调查AAD-->企业应用程序-->权限时,我可以在Graph Explorer应用程序中看到用户同意权限,但在我的应用程序中看不到。

  • 我是Spring-Boot的新手。我想创建一个API,它将具有基于角色的访问权限和基于JWT令牌的身份验证。但是,无法实现。 我没有使用JPA 安全配置 控制器 授权过滤器 在这种情况下,除了具有主管角色的用户之外,不应访问api/username。

  • 我不熟悉Azure和sharepoint与Java的集成。 我正在尝试将Java与Sharepoint整合。Sharepoint-Office 365在Azure ADFS提供。我需要编写一个Java程序进行身份验证,然后使用Sharepoint提供的RESTful APIs访问文件。Azure正在使用WS-Federation身份验证过程。我一直在试图寻找帮助我使用WS-F认证的代码,然后访问这

  • Magnus@Martin-HP-625~/下载/robomind$cat./robomind.sh java-jar-djava.ext.dirs=lib-dsun.java2d.ddscale=true-dsun.java2d.noddraw=true RoboMind.jar Magnus@martin-HP-625~/downloads/robomind$java-jar-djava.ex

  • 我正在尝试访问特定租户的用户OneDrive详细信息。我用过https://graph.microsoft.com/v1.0/users/{userid}/drives以获取驱动器详细信息。但它正在为在Azure目录中生成应用程序ID的管理员用户返回数据。 接下来,我需要迭代驱动器项(https://graph.microsoft.com/v1.0/users/{userId}/drives/{d