1
こんにちは、私は非常に晴れた広告とOauth2を使用してGraphAPIを使用しようとしています。Azure AD - 無効な認証トークンを返すOauth2
static let tenant = "tenant.com"
static let clientId = "22d31baa-5acf-4324-8ac1-02f0021g4f56"
static let redirectURI = URL.init(string: "test://com.test.est")
static let authority = "https://login.microsoftonline.com/\(tenant)/oauth2/authorize"
static let resourceId = "https://graph.microsoft.com"
var authContext: ADAuthenticationContext!
func getAuth(){
var error: ADAuthenticationError? = nil
authContext = ADAuthenticationContext(authority: Authentication.authority, error: &error)
authContext.acquireToken(withResource: Authentication.resourceId, clientId: Authentication.clientId, redirectUri: Authentication.redirectURI, completionBlock: {(result:ADAuthenticationResult!) in
if(result.accessToken == nil){
//Token acquisition failed
print("Failed receving Token")
}else{
//Toekn acquisition succeeded
let headers: HTTPHeaders = ["Authorization":"Bearer \(result.tokenCacheStoreItem.accessToken)"]
Alamofire.request("\(Authentication.resourceId)/me", headers: headers).responseJSON(completionHandler: { response in
print(response)
})
}
})
}
このコードは、私が手に実行され、結果:
SUCCESS: {
error = {
code = InvalidAuthenticationToken;
innerError = {
date = "2017-05-05T22:44:39";
"request-id" = "22d31baa-5acf-4324-8ac1-02f0021g4f56";
};
message = "CompactToken parsing failed with error code: -2147184105";
};
}
エラーメッセージがalamofire.requestの内側に印刷されて
私は現在、私のコードを持っています。 oauth2部分を消去すると、同じ結果が返されるため、私の権限が乱れているように感じます。私はoauth2をもう一度勉強しようとしますが、私のコードで何か間違いが起きているかどうかを教えてください。 ありがとうございました
どのようなトークンを取得しようとしていますか? [App Only Token](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-service-to-service)または[委任トークン]( https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code)?私はあなたの権限があなたに認可コードを取得したいと言っているので、あなたのgetAuth()関数は認可コードを取得するプロセスを経ていないように思えます。 –
ああ、申し訳ありません。関数名は無視してください。私はまだAzureが初めてで、複数の機能をテストしていました。 –
私が達成したいのは、トークンを取得し、トークンを使用してGraphapiにアクセスすることです。まだ苦労しています。 –