OneDrive-正确的Oauth,范围和服务端点组合

时间:2018-08-30 16:52:22

标签: microsoft-graph onedrive

我的要求是使用我的应用程序访问用户的OneDrive帐户(即能够读取/写入我的应用程序文件夹。)并获取我已注册我的应用程序的用户信息(名称/电子邮件)...并且这似乎是可行的,因为当我尝试登录自己的帐户时,我需要批准范围。将代码转换为访问令牌时遇到问题,或者在某些情况下,当我获得一个access_token时,它对于我正在使用的Service端点无效。我一直在处理以下各项的各种组合:

Oauth Options (Code Flow): 
    https://login.microsoftonline.com/common/oauth/v2/authorize
    https://login.live.com/oauth20_authorize.srf
Scopes Varients (With/Without endpoint prefix):
    Files.ReadWrite.AppFolder
    OneDrive.AppFolder
Service Endpoints:
    https://graph.microsoft.com/
    https://api.onedrive.com/

我的最新文章是上面每种方法中的第一个选项……但是,即使它在要求我批准范围并提供代码时也能识别我的应用程序。 ..它说,当尝试将代码转换为令牌时,它无法识别我的应用程序:

  

{“错误”:“ unauthorized_client”,“错误描述”:“ AADSTS70001:   找不到标识符为“ 0000000048240701”的应用程序   目录9188040d-6c67-4c5b-b112-36a304b66dad \ r \ n跟踪ID:   87f0c3e6-0d9f-4ccf-b3e9-c7d43b422800 \ r \ n相关ID:   7f440db6-eba9-4a0c-8d1f-54ae5c21d0cd \ r \ n时间戳:2018-08-30   16:12:38Z“,” error_codes“:[70001],” timestamp“:” 2018-08-30   16:12:38Z“,” trace_id“:” 87f0c3e6-0d9f-4ccf-b3e9-c7d43b422800“,” correlation_id“:” 7f440db6-eba9-4a0c-8d1f-54ae5c21d0cd“}

有人可以推荐我应该关注的正确选项吗?

我当前的代码声明:

private static String sClientID = "75417aa8-5567-4095-97fa-e09da6e1d8fb";
private static String sClientSecret = "LzAmOFF13Hgzob ... ";
private static String sCodeURL  = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=%s&scope=%s&response_type=code&state=%s&redirect_uri=%s";
private static String sScope = "https://graph.microsoft.com/User.Read https://graph.microsoft.com/Files.Read https://graph.microsoft.com/Files.ReadWrite.AppFolder";
private static String sTokenURL = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
private static String sTokenArgs = "code=%s&grant_type=authorization_code&client_id=%s&client_secret=%s&redirect_uri=%s";
private static String sAPIRootURL = "https://graph.microsoft.com/v1.0";

所有参数插入网址后均经过网址编码。

从重定向URI中删除Query参数解决了令牌请求问题。对于授权请求和令牌请求,我都使用了相同的重定向URI。首先工作的事实使我感到困惑。我还根据Marc的建议使用了“融合”应用ID。我的第一个api请求仍然出现错误:  https://graph.microsoft.com/v1.0/me/

我的Java代码是:

String _url = sAPIRootURL + "/me/";
u = new URL(_url);
uc = (HttpURLConnection) u.openConnection();
uc.setRequestMethod("GET");
uc.setRequestProperty("Authorization", String.format("Bearer %s", 
mSessionInfo.BearerToken));
uc.setRequestProperty("Content-Type", "application/json");
  

{“ code”:“ BadRequest”,“ message”:“ MIME类型'text / html,   图片/ gif,图片/ jpeg,*; q = .2, / ; q = .2'需要一个'/'字符   在类型和子类型之间,例如“文本/纯文本”。”,       “ innerError”:{         “ request-id”:“ f627bd8a-bc3a-4bb4-928a-a0daf7112368”,         “ date”:“ 2018-09-05T01:28:59”        }

我验证了令牌请求响应包括User.Read范围。

App Registration

0 个答案:

没有答案
相关问题