Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'Authorization Code Grant with PKCE' #779

Open
lyoung-confluent opened this issue Oct 11, 2024 · 2 comments
Open

Add support for 'Authorization Code Grant with PKCE' #779

lyoung-confluent opened this issue Oct 11, 2024 · 2 comments

Comments

@lyoung-confluent
Copy link
Contributor

IAM Identity Center has added support for an authorization_code grant instead of the device_code grant which provides a smoother user experience. The documentation on this is (in keeping with tradition w/AWS SSO) extremely minimal/missing altogether but I found some pretty decent comments inside the aws-toolkit-vscode repository.

You can test out the flow yourself by installing the AWS Visual Studio Code Plug-In and authenticating using the "Workforce" option. Under the hood the extension calls RegisterClient using parameters roughly like this (I've removed the codewhisper scopes):

aws --region us-west-2 sso-oidc register-client --client-name 'AWS IDE Extensions for VSCode' --client-type public --grant-types authorization_code --redirect-uris http://127.0.0.1:50383/oauth/callback --issuer-url https://d-123456.awsapps.com/start --scopes sso:account:access

It then constructs an "authorization" URL which looks like this and opens it in the user's browser:

https://oidc.us-west-2.amazonaws.com/authorize?response_type=code&client_id=<removed>&redirect_uri=http://127.0.0.1:56369/oauth/callback&scopes=sso:account:access&state=552998d0-4b83-44c3-b022-aa02005a7bd9&code_challenge=CaN1lc6CfmPsJSrYcVa68HdoA1fQIeI5Een_1a9sVA0&code_challenge_method=S256

This page skips the "device code" workflow directly landing the user on a consent screen:

image

After approving the user sees this message:
image

Internally, VSCode will take the token (sent to http://127.0.0.1:56369/oauth/callback) and exchange it using the same CreateToken API using the code and codeVerifier parameters instead of the deviceCode parameter.

From my testing the clientName can be adjusted to something like "Granted CLI" and the redirect URI can be adjusted to any localhost port however it must be in the exact form of http://127.0.0.1:<port>/oauth/callback or it will be rejected during the registration call.

@lyoung-confluent
Copy link
Contributor Author

@ravron
Copy link

ravron commented Nov 21, 2024

This AWS CLI commit implements the authorization code flow and may serve as a useful guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants