Skip to content

✨ feat(oidc): Refactor OIDC client with golang.org/x/oauth2 and go-oidc#6

Merged
SebastienLaurent-CF merged 3 commits intomainfrom
feature/oidc-refactor
Dec 4, 2025
Merged

✨ feat(oidc): Refactor OIDC client with golang.org/x/oauth2 and go-oidc#6
SebastienLaurent-CF merged 3 commits intomainfrom
feature/oidc-refactor

Conversation

@SebastienLaurent-CF
Copy link
Copy Markdown
Contributor

This commit refactors the internal/oidc package to leverage the golang.org/x/oauth2 and github.com/coreos/go-oidc libraries.

The manual implementation of OAuth2/OIDC flows, including discovery, token requests, and JSON parsing, has been replaced by robust, industry-standard libraries.

Key changes include:

  • Replaced manual OIDC discovery with oidc.NewProvider.
  • Updated token retrieval (password and client credentials grants) to use oauth2.Config and clientcredentials.Config.
  • Refactored token refreshing to use oauth2.TokenSource mechanisms.
  • Eliminated custom TokenResponse struct in favor of oauth2.Token.
  • Enhanced test suite (internal/oidc/client_test.go) to reflect new implementation and ensure compatibility with go-oidc expectations.
  • Updated cmd/authk/root.go to use token.Expiry for refresh timing, removing custom ExpiresIn logic.

This refactoring significantly improves security (due to strict validation of OIDC specs by go-oidc), maintainability, and reduces the amount of custom code.

This commit refactors the `internal/oidc` package to leverage the
`golang.org/x/oauth2` and `github.com/coreos/go-oidc` libraries.

The manual implementation of OAuth2/OIDC flows, including discovery,
token requests, and JSON parsing, has been replaced by robust,
industry-standard libraries.

Key changes include:
- Replaced manual OIDC discovery with `oidc.NewProvider`.
- Updated token retrieval (password and client credentials grants)
  to use `oauth2.Config` and `clientcredentials.Config`.
- Refactored token refreshing to use `oauth2.TokenSource` mechanisms.
- Eliminated custom `TokenResponse` struct in favor of `oauth2.Token`.
- Enhanced test suite (`internal/oidc/client_test.go`) to reflect new
  implementation and ensure compatibility with `go-oidc` expectations.
- Updated `cmd/authk/root.go` to use `token.Expiry` for refresh
  timing, removing custom `ExpiresIn` logic.

This refactoring significantly improves security (due to strict
validation of OIDC specs by go-oidc), maintainability, and reduces
the amount of custom code.
This commit addresses the recent drop in test coverage reported by Coveralls and fixes a linting issue.

Changes include:
- **internal/oidc/client_test.go:**
  - Added error checking for `w.Write` call in mock server to resolve an `errcheck` linting error.
  - Introduced `TestClient_GetToken_Password` to specifically test the Resource Owner Password Credentials flow, increasing coverage for `GetToken` function.
- **internal/env/env_test.go:**
  - Added `TestFind_NotFound` to verify error handling when a file is not found.
  - Added `TestFind_WithSeparator` to test `Find` function behavior with paths containing separators.

These changes collectively improve the overall test coverage and code quality.
The OIDC client now correctly handles "basic" and "post" as authentication method configurations, aligning with the `schema.cue` definition. Previously, only "client_secret_basic" and "client_secret_post" were recognized, leading to an "unsupported auth method" error when "basic" or "post" were used in the configuration.

This change ensures that the OIDC client initialization works as expected with the simplified auth method names defined in the schema, while maintaining backward compatibility with the more verbose OIDC standard names.
@SebastienLaurent-CF SebastienLaurent-CF merged commit 0734aea into main Dec 4, 2025
6 checks passed
@SebastienLaurent-CF SebastienLaurent-CF deleted the feature/oidc-refactor branch December 4, 2025 17: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.

1 participant