2016-11-10 11 views
7

pracuję nad aplikacją, która będzie korzystać z dwóch dostawców uwierzytelniania:AWS: Jak prawidłowo uwierzytelnić użytkownika w Cognito Pool i użyć go do tożsamości federacyjnej Cognito?

  • Facebook
  • Cognito Pool użytkownika

z byłym, nie mam żadnych problemów, wszystko działa zgodnie z przeznaczeniem. Jednak podczas konfigurowania uwierzytelniania w pulach użytkowników Cognito uderzam jedną ścianą po drugiej. Używam AWS SDK 2.4.9, XCode 8 i Swift 3.

Jestem świadomy, że zadano już wiele pytań i że istnieje wiele "przewodników". Jednak wiele z nich jest odpowiedzianych/wykonanych na przestarzałe dokumenty i SDK. Nawet oficjalna dokumentacja AWS jest nieaktualna.

etapy uwierzytelniania ja przeżywałam są następujące:

1. Konfiguracja początkowa Cognito basen

/// Set the default service configuration 
let serviceConfiguration = AWSServiceConfiguration(region: AWSRegionType.usEast1, credentialsProvider: nil) 
AWSServiceManager.default().defaultServiceConfiguration = serviceConfiguration 

/// Create a pool configuration and register it for a specific key to use later 
let poolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: appClientID, clientSecret: appClientSecret, poolId: poolID) 
AWSCognitoIdentityUserPool.registerCognitoIdentityUserPool(with: poolConfiguration, forKey: poolKey) 

/// Create a pool for a specific predefined key 
pool = AWSCognitoIdentityUserPool(forKey: poolKey) 

2. uwierzytelnienia użytkownika przed Cognito Pool użytkownika

user.getSession(username, password: password, validationData: nil).continue({ (task) -> AnyObject? in 

     if let error = task.error as? NSError { 
      completionHandler(error) 
      return nil 
     } 

     let session = task.result! as AWSCognitoIdentityUserSession 
     let token = session.idToken!.tokenString 

     let tokens : [NSString:NSString] = ["cognito-idp.us-east-1.amazonaws.com/\(self.poolID!)" as NSString : token as NSString] 
     let identityProvider = CognitoPoolIdentityProvider(tokens: tokens) 

     let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .usEast1, identityPoolId: self.identityPoolID, identityProviderManager: identityProvider) 

     /// Set the default service configuration 
     let serviceConfiguration = AWSServiceConfiguration(region: AWSRegionType.usEast1, credentialsProvider: credentialsProvider) 
     AWSServiceManager.default().defaultServiceConfiguration = serviceConfiguration 

     credentialsProvider.getIdentityId().continue({ (task) -> AnyObject? in 
      completionHandler(task.error as NSError?) 
      return nil 
     }) 

     return nil 
    }) 

3. The CognitoPoolIden tityProvider klasa

class CognitoPoolIdentityProvider : NSObject, AWSIdentityProviderManager { 

     var tokens : NSDictionary = [:] 

     init(tokens: [NSString : NSString]) { 
      self.tokens = tokens as NSDictionary 
     } 

     @objc func logins() -> AWSTask<NSDictionary> { 
      return AWSTask(result: tokens) 
     } 

    } 

4. Przechowywanie danych Cognito Federalne Tożsamości

Wszystko to przebiega bez żadnych błędów. Jednak teraz chcę, aby przechowywać dane, które mam wyciągnął z Cognito Basen do konkretnego Cognito Federalne Identity zbioru danych, więc apeluję: userProfile.synchronize().continue i otrzymuję następujące wyniki:

getCredentialsWithCognito:authenticated:customRoleArn:]_block_invoke | GetCredentialsForIdentity failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Access to Identity 'us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' is forbidden.}]

2016-11-10 10:27:16.947365 xxxxxxxx[19867:5614838] AWSiOSSDK v2.4.11 [Error] AWSIdentityProvider.m line:304 | __52-[AWSCognitoCredentialsProviderHelper getIdentityId]_block_invoke.255 | GetId failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Unauthenticated access is not supported for this identity pool.}] 2016-11-10 10:27:16.947726 xxxxxxxx[19867:5614838] AWSiOSSDK v2.4.11 [Error]

AWSCredentialsProvider.m line:577 | __44-[AWSCognitoCredentialsProvider credentials]_block_invoke.352 | Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Unauthenticated access is not supported for this identity pool.}] 2016-11-10 10:27:16.948452 xxxxxxxx[19867:5614838] AWSiOSSDK v2.4.11 [Error]

AWSCognitoDataset.m line:352 | __30-[AWSCognitoDataset syncPull:]_block_invoke | Unable to list records: Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Unauthenticated access is not supported for this identity pool.} [10:27:16]: saveSettings AWS task error: The operation couldn’t be completed. (com.amazonaws.AWSCognitoIdentityErrorDomain error 8.)

Po zmianie poziomu dziennika Widzę, co następuje:

//REQUEST

2016-11-10 10:33:08.095735 xxxxxxxx[19874:5616142] AWSiOSSDK v2.4.11 [Debug] AWSURLSessionManager.m line:543 | -[AWSURLSessionManager printHTTPHeadersAndBodyForRequest:] | Request body: {"IdentityId":"us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"}

//RESPONSE

2016-11-10 10:33:08.714268 xxxxxxxx[19874:5616154] AWSiOSSDK v2.4.11 [Debug] AWSURLSessionManager.m line:553 | -[AWSURLSessionManager printHTTPHeadersForResponse:] | Response headers: { Connection = "keep-alive"; "Content-Length" = 129; "Content-Type" = "application/x-amz-json-1.1"; Date = "Thu, 10 Nov 2016 09:33:08 GMT"; "x-amzn-ErrorMessage" = "Access to Identity 'us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx' is forbidden."; "x-amzn-ErrorType" = "NotAuthorizedException:"; "x-amzn-RequestId" = "b0ac6fb0-a728-11e6-8413-1fdb846185bb"; }

Powyższe żądanie dotyczy wywołania interfejsu API GetID. Najwyraźniej nie pasuje do formatu żądania z Dokumentów AWS: http://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetId.html.

Według klasy AWSServiceManager mamy to:

/** 
The default service configuration object. This property can be set only once, and any subsequent setters are ignored. 
*/ 
@property (nonatomic, copy) AWSServiceConfiguration *defaultServiceConfiguration; 

Oznacza to, że ustawienie nowej konfiguracji usług jest bez sensu, ale nie widzę innego sposobu, aby odświeżyć poświadczenia, że ​​mam uzyskane przez Cognito Pool użytkownika poświadczenie.

To wszystko. Jakieś pomysły?

Dzięki

+0

skąd pochodzi ten użytkownik. Czy możesz wymienić typ użytkownika: –

Odpowiedz

1

Wydaje się od błędu otrzymujesz

Access to Identity 'us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' is forbidden 

że poświadczenia, że ​​uzyskane w pierwszej części nie może uzyskać dostępu do tożsamości dokonaniu połączenia synchronizacji z tak swoją tożsamość prawdopodobnie zmienił .

+0

Czy będziesz w stanie podać więcej szczegółów na ten temat? Otrzymuję podobny błąd – mm24

Powiązane problemy