(tokType string, domain string)
| 358 | } |
| 359 | |
| 360 | func requestAccessCredential(tokType string, domain string) (storedCredential, error) { |
| 361 | if err := ensureOAuthAppCredentials(tokType); err != nil { |
| 362 | return storedCredential{}, err |
| 363 | } |
| 364 | |
| 365 | conf := oauthConfig(tokType, domain) |
| 366 | verifier := generateOAuthVerifier() |
| 367 | state := generateOAuthState() |
| 368 | authCodeURL := conf.AuthCodeURL(state, |
| 369 | oauth2.S256ChallengeOption(verifier), |
| 370 | oauth2.SetAuthURLParam(tokenAccessTypeParam, tokenAccessTypeOffline), |
| 371 | ) |
| 372 | |
| 373 | fmt.Printf("1. Go to %v\n", authCodeURL) |
| 374 | fmt.Printf("2. Click \"Allow\" (you might have to log in first).\n") |
| 375 | fmt.Printf("3. Copy the authorization code.\n") |
| 376 | fmt.Printf("Enter the authorization code here: ") |
| 377 | |
| 378 | code, err := readAuthorizationCode() |
| 379 | if err != nil { |
| 380 | return storedCredential{}, err |
| 381 | } |
| 382 | token, err := exchangeAuthorizationCode(currentContext(), conf, code, verifier) |
| 383 | if err != nil { |
| 384 | return storedCredential{}, authExchangeFailedErrorfWithDetails("exchange authorization code: %w", map[string]any{ |
| 385 | "token_type": authTokenTypeName(tokType), |
| 386 | }, err) |
| 387 | } |
| 388 | if token == nil || token.AccessToken == "" { |
| 389 | return storedCredential{}, authExchangeFailedErrorWithDetails("authorization did not return an access token", map[string]any{ |
| 390 | "token_type": authTokenTypeName(tokType), |
| 391 | }) |
| 392 | } |
| 393 | if token.RefreshToken == "" { |
| 394 | return storedCredential{}, authExchangeFailedErrorWithDetails("authorization did not return a refresh token", map[string]any{ |
| 395 | "token_type": authTokenTypeName(tokType), |
| 396 | }) |
| 397 | } |
| 398 | return storedCredentialFromOAuthToken(token, conf.ClientID), nil |
| 399 | } |
| 400 | |
| 401 | func refreshStoredCredential(tokType string, domain string, credential storedCredential) (storedCredential, error) { |
| 402 | appKey := credential.AppKey |
no test coverage detected