Azure AD 테넌트를 사용하여 android 용 AppAuth 테스트 앱을 만들었지 만 제대로 작동합니다. 이제 iOS (Swift 4)와 동일하게 노력 중이며 액세스 토큰에 대한 액세스 코드를 교환하려고 할 때 실패합니다. 오류가 반환되지 않습니다. idToken은 있지만 accessToken이나 refreshToken은 없습니다. 다른 오류는 없습니다. 무슨 일이 일어나고 있는지 잘 모르겠다. 액세스 토큰이 없으면 그래프를 쿼리 할 수 없습니다. 저는 Azure AD v2를 사용하고 있습니다. 다음은 내 코드의 일부입니다.AppAuth iOS 토큰 교환 문제 Azure AD
func appAuthAuthorize(authConfig: AuthConfig) {
let serviceConfiguration = OIDServiceConfiguration(
authorizationEndpoint: NSURL(string: authConfig.authEndPoint)! as URL,
tokenEndpoint: NSURL(string: authConfig.tokenEndPoint)! as URL)
let request = OIDAuthorizationRequest(configuration: serviceConfiguration, clientId: authConfig.clientId, scopes: [OIDScopeOpenID, OIDScopeProfile], redirectURL: NSURL(string: authConfig.redirectUri)! as URL, responseType: OIDResponseTypeCode, additionalParameters: nil)
doAppAuthAuthorization(authRequest: request)
}
func doAppAuthAuthorization(authRequest: OIDAuthorizationRequest) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.currentAuthorizationFlow = OIDAuthorizationService.present(authRequest, presenting: self, callback: {
(authorizationResponse, error) in
if (authorizationResponse != nil) {
self.authState = OIDAuthState(authorizationResponse: authorizationResponse!)
self.logMessage(message: "Got authorization code: \(String(describing: self.authState?.lastAuthorizationResponse.authorizationCode))")
self.doTokenRequest()
} else {
self.authState = nil
self.logMessage(message: "Authorization error: \(String(describing: error?.localizedDescription))")
}
})
}
func doTokenRequest() {
let tokenExchangeRequest = authState?.lastAuthorizationResponse.tokenExchangeRequest()
OIDAuthorizationService.perform(tokenExchangeRequest!) {
tokenResponse, error in
if tokenResponse == nil{
self.logMessage(message: "Token exchange error: \(error!.localizedDescription)")
} else {
self.authState?.update(with: tokenResponse!, error: error)
self.saveState()
self.logMessage(message: "Received token response with accesToken: \(tokenResponse!.idToken!)")
self.logMessage(message: "Received token response with accesToken: \(tokenResponse!.refreshToken!)")
self.logMessage(message: "Received token response with accesToken: \(tokenResponse!.accessToken!)")
self.retrieveUserProfile()
}
self.authState?.update(with: tokenResponse, error: error)
}
}
당신이 PowerShell을 사용하여 그래프 API에 응용 프로그램을 등록 있나요? v1.6에서는이 작업을 수행해야하지만 v2에서는 필요하지 않은 작업입니다. – Pytry
하지 않아도됩니다. 내 Android 앱 및 MSAL을 사용하는 iOS 예가 정상적으로 작동합니다. 그것의 유일한 AppAuth가 제대로 작동하지 않습니다. – Igor
아, 그래. OpenIdConnect 편안한 플로우를 제공 할 수는 있지만 MSAL은 사용한 적이 없습니다. 죄송합니다. – Pytry