我正在使用一个使用Alexa语音服务并维护不同用户的应用程序,因此用户需要使用亚马逊(LWA)登录.我已经实现了它,就像它是在文档中编写的,它可以完美地工作.
LWA docs:https://developer.amazon.com/de/docs/login-with-amazon/use-sdk-ios.html
AMZNAuthorizationManager.shared().authorize(request, withHandler: {(result : AMZNAuthorizeResult?, userDidCancel : Bool, error : Error?) -> () in
if error != nil {
// Handle errors from the SDK or authorization server.
}
else if userDidCancel {
// Handle errors caused when user cancels login.
}
else {
// Authentication was successful.
// Obtain the access token and user profile data.
self.accessToken = result!.token
self.user = result!.user!
}
})
Run Code Online (Sandbox Code Playgroud)
此外,我需要从DynamoDB检索信息,该信息使用Cognito进行身份验证.正如文档中所述,应该有一种方法将访问令牌从LWA传递给Cognito,但我找不到合适的位置.他们说LWA提供了AMZNAccessTokenDelegate,但它没有提供.委托方法提供Cognito需要的API结果.下面Cognito文档中的链接指的是我在上面发布的LWA文档中的完全相同的链接.
Cognito文档:https://docs.aws.amazon.com/cognito/latest/developerguide/amazon.html
func requestDidSucceed(apiResult: APIResult!) {
if …Run Code Online (Sandbox Code Playgroud) amazon-web-services ios amazon-cognito aws-sdk login-with-amazon