【发布时间】:2015-01-13 21:50:28
【问题描述】:
我正在使用 Azure AD 在 O365 中预配和许可新用户,它运行良好,但是我需要一些进一步的 O365 功能(即能够导出用户的联系人)。我注意到您的应用有权执行此操作:
我可以获得一个不记名令牌来执行与此代码类似的所有其他 REST 调用(在 ruby 中使用 httparty):
domain = "example.com"
api_version = "1.5"
auth_url = "https://login.windows.net/#{domain}/oauth2/token?api-version=#{api_version}"
auth_body = {"grant_type" => "client_credentials", "client_id" => @client_id, "client_secret" => @client_secret}
auth_headers = {"Content-Type" => "application/x-www-form-urlencoded"}
token_resp = HTTParty.post(auth_url, :headers => auth_headers, :body => auth_body)
bearer_token = "Bearer #{token_resp['access_token']}"
它在拨打https://graph.windows.net/ 时效果很好,但是当我尝试在 O365 Exchange 上拨打电话时:
request_headers={"Authorization" => bearer_token, "Content-Type"=>"application/json"}
request = HTTParty.get("https://outlook.office365.com/api/v1.0/users/user@example.com", :headers => request_headers)
或
request = HTTParty.get("https://api.office.com/discovery/v1.0/me/services", :headers => request_headers)
我收到以下回复:
HTTParty::Response:0x7fea2f8b0e40 parsed_response={"error"=>{"code"=>"-2147024891, System.UnauthorizedAccessException", "message"=>"访问被拒绝。你做 无权执行此操作或访问此 资源。"}}, @response=#, @headers={"cache-control"=>["private, max-age=0"], “传输编码”=>[“分块”], "content-type"=>["application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"], "expires"=>["Mon, 29 Dec 2014 19 :27:04 GMT"], "last-modified"=>["星期二, 2015 年 1 月 13 日 19:27:04 GMT"], "服务器"=>["Microsoft-IIS/8.0"], "x-correlationid"=>["595d3bd9-94f7-40fe-b4ed-c3a28cc74cdb"], "x-usersessionid"=>["595d3bd9-94f7-40fe-b4ed-c3a28cc74cdb"], "x-officefe"=>["OdcFrontEnd_IN_10"], "x-officeversion"=>["16.0.3705.3001"], "x-officecluster"=>["scus-odc.officeapps.live.com"], "p3p"=>["CP=\"CAO DSP COR ADMa DEV CONi TELi CUR PSA PSD TAI IVDi OUR SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR\""], "odata-version"=>["4.0"], "x-aspnet-version"=>["4.0.30319"], "x-powered-by"=>["ASP.NET"], "date"=>["2015 年 1 月 13 日星期二 19:27:03 GMT"], "connection"=>["close"]}>
我在这里遗漏了什么吗?如何使用我的应用程序的不记名令牌来访问 Exchange Online API?有这方面的文档吗?我似乎找不到关于这个主题的任何内容。
【问题讨论】:
标签: ruby ms-office office365 azure-active-directory