1

我應該在rails上集成cognito + ruby​​。AWS Cognito + RubyOnRails在後端獲取用戶信息。 Aws :: CognitoIdentityProvider :: Errors :: NotAuthorizedException

我的用戶用cognito登錄了默認登錄頁面,並用url params重定向到了我的頁面。

https://development-my-site.auth.us-west-2.amazoncognito.com/oauth2/authorize?client_id=62i222222222222&redirect_uri=https://c3ffec02.ngrok.io/auth/cognito/callback&response_type=token&scope=email+openid+profile

重定向後,我有PARAMS

id_token=eyJraWQiOiIyYThzTzY3........ 
&access_token=eyJraWQiOiJDa0I2NGJsUFJKTWZrNGlV..... 
&expires_in=3600 
&token_type=Bearer 

我應該從URL access_token,並傳遞給後臺在用戶認證。

在後端我使用AWS-SDK ```

def client 
    @client ||= Aws::CognitoIdentityProvider::Client.new(region: options.aws_region) 
    end 

    def get_user_info(params) 
    client.get_user(access_token: params['access_token']) 
    end 

```

但結果我有錯誤Aws::CognitoIdentityProvider::Errors::NotAuthorizedException (Access Token does not have required scopes):

我應該得到用戶的信息做什麼?

回答

3

您需要的範圍aws.cognito.signin.user.admin添加到您的查詢:

https://development-my-site.auth.us-west-2.amazoncognito.com/oauth2/authorize? 
client_id=62i222222222222 
    &redirect_uri=https://c3ffec02.ngrok.io/auth/cognito/callback 
    &response_type=token 
    &scope=email+openid+profile+aws.cognito.signin.user.admin 

,並允許它在cognito控制檯下允許的OAuth範圍