AppAuth iOS 實作 3-實作解析OAuth2.0串接第三方取得帳號資訊

(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中

--

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Peggy Tsai 

Peggy Tsai 

iOS & Golang 隨手記 www.linkedin.com/in/peggytsaifc 歡迎+Linkedin交流~

More from Medium

IOS Unit Testing in Swift

5 Epiphanies from My First [Digital] WWDC

Method dispatch in Swift protocols

Lets coding with together MVVM + RxSwift ( Approach of function in view model )