MCPcopy Create free account
hub / github.com/dropbox/dbxcli / requestAccessCredential

Function requestAccessCredential

cmd/auth.go:360–399  ·  view source on GitHub ↗
(tokType string, domain string)

Source from the content-addressed store, hash-verified

358}
359
360func 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
401func refreshStoredCredential(tokType string, domain string, credential storedCredential) (storedCredential, error) {
402 appKey := credential.AppKey

Callers 2

getAccessCredentialFunction · 0.85
requestAccessTokenFunction · 0.85

Calls 7

oauthConfigFunction · 0.85
currentContextFunction · 0.85
authTokenTypeNameFunction · 0.85

Tested by

no test coverage detected