Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pkg/auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ const (
DefaultClientID = "hmFrJn9hKDV2N02M"
RedirectURI = "http://localhost"

// OAuth scopes - openid for the MCP server flow
DefaultScope = "openid email"

// tokenExchangeTimeout bounds the token/refresh HTTP calls so a stalled auth
// server surfaces as an error instead of hanging the CLI indefinitely.
tokenExchangeTimeout = 30 * time.Second
Expand Down Expand Up @@ -143,7 +140,6 @@ func NewOAuthConfig() (*OAuthConfig, error) {
config := &oauth2.Config{
ClientID: clientID,
RedirectURL: redirectURI,
Scopes: strings.Split(DefaultScope, " "),
Endpoint: oauth2.Endpoint{
AuthURL: authorizeURL(authBaseURL),
TokenURL: tokenURL(authBaseURL),
Expand Down Expand Up @@ -292,7 +288,6 @@ func RefreshTokens(ctx context.Context, tokens *TokenStorage) (*TokenStorage, er
values.Set("grant_type", "refresh_token")
values.Set("refresh_token", tokens.RefreshToken)
values.Set("client_id", tokenOAuthClientID(tokens))
values.Set("scope", DefaultScope)
if tokens.OrgID != "" {
values.Set("org_id", tokens.OrgID)
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/auth/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -34,6 +35,22 @@ func TestNewOAuthConfigUsesAuthOverrides(t *testing.T) {
}
}

// The CLI names no scopes: the authorization server's consent page decides
// what the login may do.
func TestAuthorizationRequestNamesNoScope(t *testing.T) {
cfg, err := NewOAuthConfig()
if err != nil {
t.Fatalf("NewOAuthConfig() error = %v", err)
}
authURL, err := url.Parse(cfg.Config.AuthCodeURL(cfg.State))
if err != nil {
t.Fatalf("AuthCodeURL() is not a URL: %v", err)
}
if authURL.Query().Has("scope") {
t.Fatalf("authorization request names scope %q", authURL.Query().Get("scope"))
}
}

func TestTokenRefreshConfigPrefersStoredValues(t *testing.T) {
t.Setenv("KERNEL_AUTH_BASE_URL", "https://auth.dev.onkernel.com")
t.Setenv("KERNEL_OAUTH_CLIENT_ID", "staging-client-id")
Expand Down Expand Up @@ -115,6 +132,9 @@ func TestRefreshTokensPreservesProjectScope(t *testing.T) {
if got, want := r.Form.Get("refresh_token"), "refresh-old"; got != want {
t.Fatalf("refresh_token = %q, want %q", got, want)
}
if r.Form.Has("scope") {
t.Fatalf("refresh request names scope %q", r.Form.Get("scope"))
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"access_token": "access-new",
Expand Down
Loading