Skip to content

feat: CLI SSO login using the OAuth 2.0 Device Code Authorization Grant (Alpha) (#16069) - #17041

Closed
dgaponcic wants to merge 1 commit into
argoproj:masterfrom
dgaponcic:sso-oauth2-device-code-authz
Closed

dgaponcic wants to merge 1 commit into
argoproj:masterfrom
dgaponcic:sso-oauth2-device-code-authz

Conversation

@dgaponcic

@dgaponcic dgaponcic commented Jan 30, 2024 •

Copy link
Copy Markdown

Closes: #16069

This PR updates the oauth2Login function to support multiple OAuth flows.

Instead of starting an HTTP server and opening a browser, a URL is printed on the screen that can be opened from elsewhere to finish the authorization process (as described in the rfc).
Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

@dgaponcic
dgaponcic requested review from a team as code owners January 30, 2024 16:11
@codecov

codecov Bot commented Jan 30, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 3.63636% with 53 lines in your changes are missing coverage. Please review.

Project coverage is 49.24%. Comparing base (f87897c) to head (e288340).
Report is 171 commits behind head on master.

❗ Current head e288340 differs from pull request most recent head 22b7cb3. Consider uploading reports for the commit 22b7cb3 to get more accurate results

Files Patch % Lines
cmd/argocd/commands/login.go 0.00% 53 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17041      +/-   ##
==========================================
- Coverage   49.73%   49.24%   -0.50%     
==========================================
  Files         274      274              
  Lines       48948    48160     -788     
==========================================
- Hits        24343    23715     -628     
+ Misses      22230    22100     -130     
+ Partials     2375     2345      -30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dgaponcic
dgaponcic force-pushed the sso-oauth2-device-code-authz branch from e288340 to f9b1597 Compare May 13, 2024 12:46
@dgaponcic dgaponcic changed the title feat: CLI SSO login using the OAuth 2.0 Device Code Authorization Grant (#16069) feat: CLI SSO login using the OAuth 2.0 Device Code Authorization Grant (#16069) (Alpha) May 13, 2024
@dgaponcic dgaponcic changed the title feat: CLI SSO login using the OAuth 2.0 Device Code Authorization Grant (#16069) (Alpha) feat: CLI SSO login using the OAuth 2.0 Device Code Authorization Grant (Alpha) (#16069) May 13, 2024
@dgaponcic
dgaponcic force-pushed the sso-oauth2-device-code-authz branch from f9b1597 to 4335d9b Compare May 13, 2024 14:56
Signed-off-by: Diana Gaponcic <diana.gaponcic@cern.ch>
@rochaporto

Copy link
Copy Markdown
Contributor

Could someone have a look at this one?

data.Set("grant_type", grant_type)
data.Set("device_code", deviceCodeResponseBody.DeviceCode)

tokenRequest, _ := http.NewRequest("POST", oidcSettings.TokenURL, strings.NewReader(data.Encode()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there an error we should be handling here?

return tokenString, refreshToken
}

func oauth2LoginBrowserless(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a pretty big function.... can it be broken down into smaller pieces, ideally things that can be unit-tested?

httpClient := &http.Client{}
data := url.Values{}
data.Set("client_id", oauth2conf.ClientID)
deviceCodeRequest, _ := http.NewRequest("POST", oidcSettings.DeviceURL, strings.NewReader(data.Encode()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs error handling?

Comment on lines +428 to +429
_, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we do without this context? Looks unused.

@dkarpele

dkarpele commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Hi @crenshaw-dev
I continue this work in #29198. Please review here. Thanks

@ppapapetrou76

Copy link
Copy Markdown
Contributor

closing this in favor of #29198

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.

CLI SSO login using the OAuth 2.0 Device Code Authorization Grant

5 participants