[GH-ISSUE #6840] Cognito scopes should be space separated #10650

Closed
opened 2026-04-13 06:54:35 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @at0dd on GitHub (Dec 17, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6840

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Follow the Cognito documentation to configure the Cognito social sign-on.

Current vs. Expected behavior

When trying to log in, the scopes in the authorize url are separated by a + when they should be separated by a space, per the AWS documentation.

What version of Better Auth are you using?

1.4.7

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000",
    "release": "25.2.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.32 GB"
  },
  "node": {
    "version": "v25.2.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.0.10"
    },
    {
      "name": "react",
      "version": "19.2.3"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.4.7",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Package

Auth config (if applicable)

import { betterAuth } from "better-auth";
export const auth = betterAuth({
  socialProviders: {
    cognito: {
      clientId: process.env.COGNITO_CLIENT_ID as string,
      clientSecret: process.env.COGNITO_CLIENT_SECRET as string,
      domain: process.env.COGNITO_DOMAIN as string,
      region: process.env.COGNITO_REGION as string,
      userPoolId: process.env.COGNITO_USERPOOL_ID as string,
    },
  },
});

Additional context

In testing I get an invalid scope error, but if I manually update the url to have %20 between each scope the login process works.

Originally created by @at0dd on GitHub (Dec 17, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6840 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Follow the [Cognito documentation](https://www.better-auth.com/docs/authentication/cognito) to configure the Cognito social sign-on. ### Current vs. Expected behavior When trying to log in, the scopes in the authorize url are separated by a `+` when they should be separated by a space, per the [AWS documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html). ### What version of Better Auth are you using? 1.4.7 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000", "release": "25.2.0", "cpuCount": 10, "cpuModel": "Apple M1 Pro", "totalMemory": "16.00 GB", "freeMemory": "0.32 GB" }, "node": { "version": "v25.2.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "next", "version": "16.0.10" }, { "name": "react", "version": "19.2.3" } ], "databases": null, "betterAuth": { "version": "^1.4.7", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; export const auth = betterAuth({ socialProviders: { cognito: { clientId: process.env.COGNITO_CLIENT_ID as string, clientSecret: process.env.COGNITO_CLIENT_SECRET as string, domain: process.env.COGNITO_DOMAIN as string, region: process.env.COGNITO_REGION as string, userPoolId: process.env.COGNITO_USERPOOL_ID as string, }, }, }); ``` ### Additional context In testing I get an invalid scope error, but if I manually update the url to have `%20` between each scope the login process works.
GiteaMirror added the locked label 2026-04-13 06:54:35 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 17, 2025):

(tag @better-auth-agent if you would like an answer from the Agent)

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3667519175 --> @better-auth-agent[bot] commented on GitHub (Dec 17, 2025): (tag @better-auth-agent if you would like an answer from the Agent) _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 17, 2025):

Hi @at0dd! I'm Dosu and I’m helping the better-auth team.

The scopes in the Cognito authorize URL are joined with a space in Better Auth, but when the URL is constructed, the URLSearchParams API encodes spaces as + by default. This is standard behavior in browsers and Node.js, but AWS Cognito's documentation specifies scopes should be space-separated, without clarifying if encoded spaces must be %20 instead of + (source). There are no existing tickets or recent changes addressing this in Better Auth.

If Cognito strictly requires %20 for spaces, you could work around this by customizing the authorization URL construction, for example using the genericOAuth plugin, but this approach is hacky and not officially supported (discussion). There isn't a built-in config option to change the encoding for scopes in the Cognito provider.

If you need to patch this, you would need to modify the code that builds the authorize URL to replace + with %20 after URL encoding, or use a custom OAuth provider setup.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3667523698 --> @dosubot[bot] commented on GitHub (Dec 17, 2025): <!-- Greeting --> Hi @at0dd! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The scopes in the Cognito authorize URL are joined with a space in Better Auth, but when the URL is constructed, the `URLSearchParams` API encodes spaces as `+` by default. This is standard behavior in browsers and Node.js, but AWS Cognito's documentation specifies scopes should be space-separated, without clarifying if encoded spaces must be `%20` instead of `+` ([source](https://github.com/better-auth/better-auth/blob/94592d0a6789a6a66284bc0e73c56860e502a31d/packages/core/src/oauth2/create-authorization-url.ts#L43-L86)). There are no existing tickets or recent changes addressing this in Better Auth. If Cognito strictly requires `%20` for spaces, you could work around this by customizing the authorization URL construction, for example using the `genericOAuth` plugin, but this approach is hacky and not officially supported ([discussion](https://github.com/better-auth/better-auth/discussions/5191)). There isn't a built-in config option to change the encoding for scopes in the Cognito provider. If you need to patch this, you would need to modify the code that builds the authorize URL to replace `+` with `%20` after URL encoding, or use a custom OAuth provider setup. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/443e1631-114d-40d3-b155-0c8992697821?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/443e1631-114d-40d3-b155-0c8992697821?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/443e1631-114d-40d3-b155-0c8992697821?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/443e1631-114d-40d3-b155-0c8992697821?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/443e1631-114d-40d3-b155-0c8992697821?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/443e1631-114d-40d3-b155-0c8992697821?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/443e1631-114d-40d3-b155-0c8992697821?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20scopes%20in%20the%20Cognito%20authorize%20URL%20are%20joined%20with%20a%20space%20in%20Better%20Auth%2C%20but%20when%20the%20URL%20is%20constructed%2C%20the%20%60URLSearchParams%60%20API%20encodes%20spaces%20as%20%60%2B%60%20by%20default.%20This%20is%20standard%20behavior%20in%20browsers%20and%20Node.js%2C%20but%20AWS%20Cognito%27s%20documentation%20specifies%20scopes%20should%20be%20space-separated%2C%20without%20clarifying%20if%20encoded%20spaces%20must%20be%20%60%2520%60%20instead%20of%20%60%2B%60%20%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/94592d0a6789a6a66284bc0e73c56860e502a31d/packages/core/src/oauth2/create-authorization-url.ts%23L43-L86%29%29.%20There%20are%20no%20existing%20tickets%20or%20recent%20changes%20addressing%20this%20in%20Better%20Auth.%0A%0AIf%20Cognito%20strictly%20requires%20%60%2520%60%20for%20spaces%2C%20you%20could%20work%20around%20this%20by%20customizing%20the%20authorization%20URL%20construction%2C%20for%20example%20using%20the%20%60genericOAuth%60%20plugin%2C%20but%20this%20approach%20is%20hacky%20and%20not%20officially%20supported%20%28%5Bdiscussion%5D%28https%3A//github.com/better-auth/better-auth/discussions/5191%29%29.%20There%20isn%27t%20a%20built-in%20config%20option%20to%20change%20the%20encoding%20for%20scopes%20in%20the%20Cognito%20provider.%0A%0AIf%20you%20need%20to%20patch%20this%2C%20you%20would%20need%20to%20modify%20the%20code%20that%20builds%20the%20authorize%20URL%20to%20replace%20%60%2B%60%20with%20%60%2520%60%20after%20URL%20encoding%2C%20or%20use%20a%20custom%20OAuth%20provider%20setup.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6840)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10650