aws-amplify / aws-amplify/amplify-cli

Allowing multiple redirectSignIn/redirectSignOut urls breaks federated auth

Open
#2,792 17 comments 34 reactions 0 assignees View on GitHub
auth feature-request p3
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

**Describe the bug**
Using the Amplify CLI to add multiple `redirectSignIn`/`redirectSignOut` URLs results in a broken config

**To Reproduce**
Steps to reproduce the behavior:
1. Use `amplify add auth` to set up a federated auth config
2. Add a `redirectSignIn` url, e.g. `http://localhost:3000`
3. Add an additional `redirectSignIn` url, e.g. `https://d32tfey1ge36f1.cloudfront.net/`
4. Add the same for `redirectSignOut` urls
5. See the config has the two urls joined by a comma, e.g. `"redirectSignIn": "http://localhost:3000/,https://d32tfey1ge36f1.cloudfront.net/",`
6. Attempt to authenticate in the app and see the error due to the comma-separated urls not being a valid format for the OAuth provider

**Expected behavior**
The CLI should not allow multiple URLs to be entered if that results in a non-working config

**Additional context**
Using Google as the OAuth provider, the following invalid URI is generated due to the multiple comma-separated urls being set as the `redirect_uri` value:

```
https://example-dev.auth.us-west-2.amazoncognito.com/oauth2/authorize?redirect_uri=http%3A%2F%2Flocalhost%3A3000%2F%2Chttps%3A%2F%2Fd32tfey1ge36f1.cloudfront.net%2F&response_type=code&client_id=23r4j2asdfelvhasdfas8md4t&identity_provider=Google&scopes=phone%2Cemail%2Copenid%2Cprofile%2Caws.cognito.signin.user.admin&state=ymIeVUG2ez8pbasdfasdfWiG1u42Frn&code_challenge=asdfasdfasdfb7aLeB8FAQv_V7P9TTyZzGasdfasffj0Us&code_challenge_method=S256
```

Notice the `redirect_uri` parameter has both URLs.

I solved this problem in my react.js app by overriding the `awsmobile` config something like this:
```
import awsmobile from './aws-exports';

const { NODE_ENV } = process.env;
const DEFAULT_URL = 'http://localhost:3000/';

if (NODE_ENV === 'development') {
awsmobile.oauth.redirectSignIn = DEFAULT_URL;
awsmobile.oauth.redirectSignOut = DEFAULT_URL;
}
export default awsmobile;
```

Contributor guide

Open the contributing guide

Research direction

Start with the `amplify add auth` flow and follow how multiple redirectSignIn and redirectSignOut values are collected and written into the generated config. Reproduce the comma-separated values with a federated Google provider, then verify that the CLI prevents or correctly handles multiple URLs without producing an invalid redirect_uri.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
authentication, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.