Skip to content

fix(auth): skip Nais login when already authenticated - #782

Merged
jhrv merged 1 commit into
mainfrom
idempotent_login
Sep 30, 2026
Merged

jhrv merged 1 commit into
mainfrom
idempotent_login

Conversation

@jhrv

@jhrv jhrv commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

📝 Changelog preview

Below is a preview of the Changelog that will be added to the next release. Only commit messages that follow the Conventional Commits specification will be included in the Changelog.

v5.50.2 - 2026-09-30

Full Changelog: v5.50.1...v5.50.2

🐛 Bug Fixes

  • (auth) Skip Nais login when already authenticated (da47267)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Authentication-expiry errors from access-token retrieval should trigger login instead of being returned.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Skips the Nais OIDC login flow when a valid session already exists.

Changes:

  • Validates the stored user and access token.
  • Reports the authenticated email when login is skipped.
File Description
internal/​naisapi/​auth/​oidc.go Adds existing-session detection to OIDC login.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/naisapi/auth/oidc.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

An access-token authentication failure is returned instead of continuing with the requested login flow.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused implementation is consistent with existing authentication behavior and is covered by a representative test.

Review effort: Balanced
Findings: None

@jhrv
jhrv merged commit 5975a51 into main Sep 30, 2026
23 checks passed
@jhrv
jhrv deleted the idempotent_login branch September 30, 2026 14:30
Comment on lines +74 to +78
if err == nil {
// The access token may be expired, in which case it is refreshed here.
// A failed refresh means the session is gone and we must log in again.
_, err = user.AccessToken()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm nitpicking a little here, but this is already covered through OIDC() -> getOIDCUser() -> user.Valid() which attempts a refresh if the token is expired or within 10 seconds of expiry. A failed refresh also returns ErrNeedsOIDCLogin.

I also think the check to skip login should live in naisapi.Login().

OIDCLogin() should instead always run the login flow, e.g. in case we want to force a new login or switch accounts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree, fixing in new PR (#783). Nitpicking is the way tbh

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.

3 participants