Skip to content

Auth auto refresh token - #195

Merged
davixcky merged 7 commits into
mainfrom
auth-auto-refresh-token
Jul 30, 2025
Merged

davixcky merged 7 commits into
mainfrom
auth-auto-refresh-token

Conversation

@davixcky

@davixcky davixcky commented Jul 3, 2025 •

Copy link
Copy Markdown
Contributor
sequenceDiagram
    participant CLI as CLI Command
    participant API as API Client
    participant Auth as Auth Service
    participant Keyring as System Keyring

    Note over CLI,Keyring: Flow starts when any CLI command is executed

    CLI->>API: init()
    API->>Auth: ResolveAuth()
    Auth->>Keyring: Get stored auth info
    Keyring-->>Auth: Return auth info
    Auth-->>API: Return ResolvedAuth

    alt No auth found
        API-->>CLI: Return AuthNoFoundError
    else Auth exists
        API->>API: checkKeyringAuth()
        
        alt Token is expired && has refresh token
            API->>API: refreshKeyringAuth()
            API->>Auth: AuthDeviceRefreshToken API call
            Auth-->>API: New tokens (access + refresh)
            API->>Keyring: StoreAuthInKeyring(new tokens)
            API-->>CLI: Continue with refreshed tokens
        else Token is expired && no refresh token
            API-->>CLI: Return AuthExpiredError
        else Token is valid
            API-->>CLI: Continue with existing token
        end
    end
Loading

Little bit graphic usage

$ ./signadot sandbox list
Token expired
Refreshing token
NAME                      DESCRIPTION                  CLUSTER            CREATED          STATUS
pr-sd-apisvr-5941         apiserver sandbox for 5941   signadot-staging   41 minutes ago   Ready
pr-sd-apisvr-5940         apiserver sandbox for 5940   signadot-staging   23 hours ago     Ready
dev-apisvr-dorozco-test   apiserver local sandbox      signadot-staging   2 days ago       Not Ready
pr-sd-apisvr-5930         apiserver sandbox for 5930   signadot-staging   2 days ago       Ready
pr-sd-apisvr-5898         apiserver sandbox for 5898   signadot-staging   21 days ago      Ready
pr-sd-web-5866            web sandbox for 5866         signadot-staging   29 days ago      Ready
pr-sd-web-5867            web sandbox for 5867         signadot-staging   29 days ago      Ready
pr-sd-apisvr-5819         apiserver sandbox for 5819   signadot-staging   one month ago    Ready
prober-test               prober test                  signadot-staging   5 months ago     Ready
pr-sd-apisvr-5792         apiserver sandbox for 5792   signadot-staging   2 months ago     Ready
pr-sd-web-5789            web sandbox for 5789         signadot-staging   2 months ago     Ready
rollout-sbx                                            signadot-staging   2 months ago     Ready
pr-sd-apisvr-5725         apiserver sandbox for 5725   signadot-staging   2 months ago     Ready
pr-sd-apisvr-5353         apiserver sandbox for 5353   signadot-staging   2 months ago     Ready
reverse-shell-execution                                signadot-staging   4 months ago     Ready


$ ./signadot sandbox list
Token not expired
NAME                      DESCRIPTION                  CLUSTER            CREATED          STATUS
pr-sd-apisvr-5941         apiserver sandbox for 5941   signadot-staging   41 minutes ago   Ready
pr-sd-apisvr-5940         apiserver sandbox for 5940   signadot-staging   23 hours ago     Ready
dev-apisvr-dorozco-test   apiserver local sandbox      signadot-staging   2 days ago       Not Ready
pr-sd-apisvr-5930         apiserver sandbox for 5930   signadot-staging   2 days ago       Ready
pr-sd-apisvr-5898         apiserver sandbox for 5898   signadot-staging   21 days ago      Ready
pr-sd-web-5866            web sandbox for 5866         signadot-staging   29 days ago      Ready
pr-sd-web-5867            web sandbox for 5867         signadot-staging   29 days ago      Ready
pr-sd-apisvr-5819         apiserver sandbox for 5819   signadot-staging   one month ago    Ready
prober-test               prober test                  signadot-staging   5 months ago     Ready
pr-sd-apisvr-5792         apiserver sandbox for 5792   signadot-staging   2 months ago     Ready
pr-sd-web-5789            web sandbox for 5789         signadot-staging   2 months ago     Ready
rollout-sbx                                            signadot-staging   2 months ago     Ready
pr-sd-apisvr-5725         apiserver sandbox for 5725   signadot-staging   2 months ago     Ready
pr-sd-apisvr-5353         apiserver sandbox for 5353   signadot-staging   2 months ago     Ready
reverse-shell-execution                                signadot-staging   4 months ago     Ready

@davixcky
davixcky requested review from daniel-de-vera, foxish and scott-cotton and removed request for daniel-de-vera July 3, 2025 19:36
@foxish foxish changed the title auth auto refresh token uth auto refresh token Jul 10, 2025
@foxish foxish changed the title uth auto refresh token Auth auto refresh token Jul 10, 2025
Comment thread internal/config/api.go Outdated
)

var (
AuthExpiredError = errors.New("Authentication expired. Please log in using 'signadot auth login'")

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.

According to Go standards and static check, error variables should start with Err, so these should be renamed ErrAuthExpired etc.

Comment thread internal/config/api.go Outdated
if err != nil {
return err
}
authInfo = newAuthInfo

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 doesn't do anything, because Go is call by value (see https://go.dev/doc/faq#pass_by_value)

did you mean *authInfo = *newAuthInfo?

@scott-cotton scott-cotton left a comment

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.

LGTM
@davixcky can you test in a way that exercises the changes before merge?

@davixcky

Copy link
Copy Markdown
Contributor Author

Tested again, and seems to keep refreshing the token

@davixcky
davixcky merged commit 08165f6 into main Jul 30, 2025
@davixcky
davixcky deleted the auth-auto-refresh-token branch July 30, 2025 01:55
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.

2 participants