AppAuth iOS 實作 3-實作解析OAuth2.0串接第三方取得帳號資訊
Published in
Dec 20, 2021
(AppAuth iOS, openid, OAuth)
AppAuth 原理&執行專案 請參考
實作解析OAuth2.0串接第三方登入 請參考
取得使用者資訊
完整程式碼如下
取資訊之前,authState?.performAction() 會先執行performActionWithFreshTokens,token檢查有效性並且自動更換token
取得的Token跟authState?.lastTokenResponse?.accessToken 比對
發一個userinfoEndpoint的URLRequest
(透過authState的lastAuthorizationResponse.request.configuration.discoveryDocument取得userinfoEndpoint)
authState.lastAuthorizationResponse.request.configuration.discoveryDocument也可以取得一些資訊,例如:authorizationEndpoint, tokenEndpoint等
回傳的Json值即可取到資訊
同時顯示於下方textView中