2017-02-16 22 views
0

以下成功的亞馬遜Cognito登錄我一直在使用下面的示例來介紹cognito登錄到我的iPhone應用程序:如何得到的accessToken和IdToken從iOS的

https://github.com/awslabs/aws-sdk-ios-samples/tree/master/CognitoYourUserPools-Sample

這是工作好,我是在我有一個AWSCognitoIdentityUserPool對象,我可以調用currentUser()方法訪問用戶。

我在努力尋找的是我如何提取AccessTokenIdToken

在Android當量,所述AuthenticationHandleronSuccess方法具有CognitoUserSession參數又具有getIdToken()getAccessToken()

令人沮喪的是,我看到它們在輸出窗口中以json格式輸出爲AuthenticationResult,但我只是不知道如何以編程方式訪問它們?

回答

0

現在想通了:

func getSession(){ 
    self.user?.getSession().continueOnSuccessWith { (getSessionTask) -> AnyObject? in 
     DispatchQueue.main.async(execute: { 
      let getSessionResult = getSessionTask.result 
      self.idToken = getSessionResult?.idToken?.tokenString 
      self.accessToken = getSessionResult?.accessToken?.tokenString 

     }) 
     return nil 
    } 
} 
相關問題