27

I've successfully set up an AWS Cognito environment that runs on Localhost following this tutorial.

For the next step, I published the app to my external web server. I confirmed that the Cognito configuration (i.e. Client ID, Metadata Address, Region, etc) is correct. However, when I access and try to sign into the newly published public site I receive the follow error: " Client is not enabled for OAuth2.0 flows."

 Client is not enabled for OAuth2.0 flows

EDIT:

Here are my App Client Settings

App Client Settings

I would like help with what I should look into in the AWS Cognito config or the Server config settings. The server is NOT using a load balancer. I believe the issue may lie somewhere in the Reverse Proxy or HTTPS settings.

objectively C
  • 960
  • 9
  • 25

6 Answers6

47

I have seen this issue before. When making the request to Cognito, please take a close look at the redirect URL/ Call back URL you are specifying. If I remember correctly, I have seen this issue if you have a trailing '/' or a missing '/' in the redirect URL depending on what you have specified in the App Client Settings.

callo
  • 1,374
  • 8
  • 12
31

This also occurs when you set up Cognito using Cloudformation or AWS SAM, and forgot to enable AllowedOAuthFlowsUserPoolClient property to true.

Resources:
  FooBarUserPoolClient:
    Type: AWS::Cognito::UserPoolClient
    Properties:
      AllowedOAuthFlowsUserPoolClient: True # Set here
hakatashi
  • 9,006
  • 2
  • 22
  • 22
13

TLDR: In addition to previous answers, make sure your callback URL is in lower case.

Long Answer: I encountered the same error. In my case, I had copied the DNS name of my Application Load Balancer from the description window of the Load Balancer page where there was varied casing

So I put the below into the callback URL and encountered the error in question:

https://*AppLBTest*-123456123456.ap-southeast-1.elb.amazonaws.com/oauth2/idpresponse

After changing the callback URL to the below, auth worked as expected:

https://*applbtest*-123456123456.ap-southeast-1.elb.amazonaws.com/oauth2/idpresponse
Saeed Nasehi
  • 940
  • 1
  • 11
  • 27
Tsdev
  • 139
  • 1
  • 2
12

I understand OP has not asked to use terraform for this issue, but it might help someone in the future who is using terraform to create cognito user pool client. If you are getting this issue, like me, while using terraform make sure to set allowed_oauth_flows_user_pool_client to true. For example, like this:

resource "aws_cognito_user_pool_client" "client" {
  name = "<your user pool client name>"
...
  allowed_oauth_flows_user_pool_client = true
}

Here is the link to terraform doc for creating user pool client.

And here is the link to the AWS doc where it says you have to set the attribute AllowedOAuthFlowsUserPoolClient to true. This attribute maps to the same allowed_oauth_flows_user_pool_client = true in terraform.

Suraj Pandey
  • 121
  • 1
  • 2
1

For those of you coming here, and seeing the CloudFormation answer above, this is also true if you update the UserPoolClient via the cli as follows:

aws cognito-idp update-user-pool-client --user-pool-id "USER_POOL_ID" --client-id "CLIENT_ID"
  --callback-urls "https://URL_1/" "http://URL_2/" --supported-identity-providers "IDP_NAME"
  --allowed-o-auth-flows "code" --allowed-o-auth-scopes "SCOPE"

The issue is that (and it all looks ok from the console) the client is not enabled for OAuth2 flows if not explicitly specified. From the doc:

Warning If you don't provide a value for an attribute, it will be set to the default value.

.. for:

--allowed-o-auth-flows-user-pool-client

the default is not present, so you need to ensure that you add the param, so the correct call is:

aws cognito-idp update-user-pool-client --user-pool-id "USER_POOL_ID" --client-id "CLIENT_ID"
  --callback-urls "https://URL_1/" "http://URL_2/" --supported-identity-providers "IDP_NAME"
  --allowed-o-auth-flows "code" --allowed-o-auth-scopes "SCOPE" --allowed-o-auth-flows-user-pool-client

Hope this helps someone else landing here ...

-1

This issue was not a cognito problem but rather an IIS and HTTPs issue. Make sure your servers are completely HTTPS if you plan to use this AWS service. Leave comments with any questions.

objectively C
  • 960
  • 9
  • 25