Skip to content

Support device_code or authorization_code, not both#1361

Merged
synfinatic merged 1 commit into
mainfrom
limit-granttypes
May 17, 2026
Merged

Support device_code or authorization_code, not both#1361
synfinatic merged 1 commit into
mainfrom
limit-granttypes

Conversation

@synfinatic
Copy link
Copy Markdown
Owner

Apparently some AWS SSO instances throw an API error if the client tries to register using both device_code and authorization_code.

This change forces the client to always register one or the other + refresh_token support. Existing clients which have support for all 3 will be re-registed with 2.

Fixes: #1359

Copilot AI review requested due to automatic review settings May 17, 2026 20:50
Comment thread CHANGELOG.md
Comment thread CHANGELOG.md
@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

❌ Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.52%. Comparing base (02797a2) to head (fe69197).

Files with missing lines Patch % Lines
internal/sso/auth/awssso_auth.go 65.00% 6 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1361      +/-   ##
==========================================
+ Coverage   88.50%   88.52%   +0.02%     
==========================================
  Files          54       54              
  Lines        3643     3649       +6     
==========================================
+ Hits         3224     3230       +6     
  Misses        289      289              
  Partials      130      130              
Flag Coverage Δ
unittests 88.52% <75.87%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/storage/storage.go 94.88% <100.00%> (-0.12%) ⬇️
internal/sso/auth/awssso_auth.go 89.12% <65.00%> (+0.37%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02797a2...fe69197. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a regression where some AWS IAM Identity Center (SSO OIDC) configurations reject RegisterClient requests that include both device_code and authorization_code grant types, causing InvalidScopeException during aws-sso login. It updates client registration to request workflow-appropriate grant types (plus refresh_token) and forces re-registration for previously registered clients that used the problematic combination.

Changes:

  • Make RegisterClient request either device_code+refresh_token or authorization_code+refresh_token, depending on the configured auth workflow.
  • Add logic to detect “bad” historical registrations (v2.2.0/2.2.1) and transparently force a new registration.
  • Update tests and release metadata (version bump + changelog entry).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
Makefile Bumps project version to 2.2.2.
internal/storage/storage.go Adds SupportsGrantType and uses it for grant-type compatibility checks (including v2.2.0/2.2.1 migration behavior).
internal/storage/storage_test.go Adds unit test coverage for SupportsGrantType.
internal/sso/auth/awssso_auth.go Makes grant-type registration workflow-specific; adjusts validation logic; introduces scope constant; changes logout error handling.
internal/sso/auth/awssso_auth_test.go Updates workflow grant-type expectations and expands ValidAuthToken tests for PKCE vs device-code.
CHANGELOG.md Adds v2.2.2 entry and updates compare links.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +77 to +84
func (r *RegisterClientData) SupportsGrantType(gt GrantType) bool {
if len(r.GrantTypes) > 2 {
// Hack to deal with v2.2.0/2.2.1 bug where we supported all 3 grant types
// but some AWS SSO configs did not like authorization_code + device_code together
// see: https://github.com/synfinatic/aws-sso-cli/issues/1359
return false
}
for _, g := range r.GrantTypes {
Comment thread internal/sso/auth/awssso_auth.go Outdated
Comment thread internal/sso/auth/awssso_auth.go
Comment thread internal/sso/auth/awssso_auth.go Outdated
Comment thread internal/sso/auth/awssso_auth_test.go Outdated
Comment thread internal/sso/auth/awssso_auth_test.go Outdated
Comment thread internal/sso/auth/awssso_auth_test.go Outdated
Apparently some AWS SSO instances throw an API error if the client
tries to register using both device_code and authorization_code.

This change forces the client to always register one or the other +
refresh_token support. Existing clients which have support for all 3
will be re-registed with 2.

Fixes: #1359
@synfinatic synfinatic merged commit fff893f into main May 17, 2026
7 of 9 checks passed
@synfinatic synfinatic deleted the limit-granttypes branch May 17, 2026 21:40
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

Successfully merging this pull request may close these issues.

Regression in 2.2.0+: InvalidScopeException on RegisterClient.

2 participants