Skip to content

Commit 1d25235

Browse files
chaitan94claude
andcommitted
Fix SSO authentication polling to properly handle AuthorizationPendingException
The previous implementation was incorrectly treating AuthorizationPendingException as a fatal error instead of continuing to poll for authorization completion. Changes: - Import proper AWS SDK v2 error types for SSO OIDC - Use typed error checking with errors.As() instead of string matching - Handle AuthorizationPendingException and SlowDownException correctly - Add fallback string matching for compatibility - Include user-friendly polling status messages - Continue polling until user completes browser authorization This fixes the authentication flow where users would click "Allow" in the browser but the CLI would exit with an error instead of completing the login process. Tested with real AWS SSO instance and confirmed working end-to-end: - Device authorization flow starts correctly - Browser opens with verification URL and code - Polling continues while waiting for user authorization - Successfully completes login once user approves in browser - Token is cached for subsequent operations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9802146 commit 1d25235

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

awsssolib/sso.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package awsssolib
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"strings"
68
"time"
79

810
"github.com/aws/aws-sdk-go-v2/aws"
911
"github.com/aws/aws-sdk-go-v2/config"
1012
"github.com/aws/aws-sdk-go-v2/service/sso"
1113
"github.com/aws/aws-sdk-go-v2/service/ssooidc"
14+
"github.com/aws/aws-sdk-go-v2/service/ssooidc/types"
1215
)
1316

1417
const (
@@ -343,7 +346,21 @@ func performDeviceAuthorization(ctx context.Context, input LoginInput) (*Token,
343346

344347
if err != nil {
345348
// Check if it's an authorization pending error
346-
if err.Error() == "AuthorizationPendingException" {
349+
var authPendingErr *types.AuthorizationPendingException
350+
var slowDownErr *types.SlowDownException
351+
352+
if errors.As(err, &authPendingErr) {
353+
// Authorization is still pending, continue polling
354+
fmt.Printf("Waiting for authorization... (polling every %d seconds)\n", authResp.Interval)
355+
continue
356+
} else if errors.As(err, &slowDownErr) {
357+
// Slow down the polling as requested by the server
358+
fmt.Printf("Slowing down polling as requested by server...\n")
359+
time.Sleep(time.Duration(authResp.Interval) * time.Second)
360+
continue
361+
} else if strings.Contains(err.Error(), "AuthorizationPendingException") {
362+
// Fallback string check for older SDK versions
363+
fmt.Printf("Waiting for authorization... (polling every %d seconds)\n", authResp.Interval)
347364
continue
348365
}
349366
return nil, fmt.Errorf("failed to create token: %w", err)

0 commit comments

Comments
 (0)