我試圖在iOS中實現AppAuth。基本實施已經完成。似乎一切工作正常。但我沒有按預期收到代幣。即時得到錯誤Error Domain=org.openid.appauth.general Code=-4
OAuth錯誤一般代碼4 Swift - iOS的AppAuth
let authorizationEndpoint : NSURL = NSURL(string: "https://accounts.google.com/o/oauth2/v2/auth")!
let tokenEndpoint : NSURL = NSURL(string: "https://www.googleapis.com/oauth2/v4/token")!
let configuration = OIDServiceConfiguration(authorizationEndpoint: authorizationEndpoint as URL, tokenEndpoint: tokenEndpoint as URL)
let request = OIDAuthorizationRequest.init(configuration: configuration, clientId: "<MyTOKEN>", scopes: [OIDScopeOpenID], redirectURL: URL(string: "http://127.0.0.1:9004")!, responseType: OIDResponseTypeCode, additionalParameters: nil)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
// appDelegate.currentAuthorizationFlow
appDelegate.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, presenting: self, callback: { (authState, error) in
if((authState) != nil){
print("Got authorization tokens. Access token: \(authState?.lastTokenResponse?.accessToken)")
}else{
print("Authorization error \(error?.localizedDescription)")
}
})
你設置clientSecret與請求 – Govaadiyo
啊,不。它在文檔「https:// github.com/openid/AppAuth-iOS」中沒有提及如何做到這一點? –
在文檔中找到它,但'client_secret \t從API控制檯獲取的客戶端密鑰。對於註冊爲Android,iOS或Chrome應用程序的客戶端,此值不是必需的,因爲即時消息在iOS中使用它不是必需的嗎? –