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

Function refreshStoredCredential

cmd/auth.go:401–433  ·  view source on GitHub ↗
(tokType string, domain string, credential storedCredential)

Source from the content-addressed store, hash-verified

399}
400
401func refreshStoredCredential(tokType string, domain string, credential storedCredential) (storedCredential, error) {
402 appKey := credential.AppKey
403 if appKey == "" {
404 appKey = oauthCredentials(tokType)
405 }
406 if strings.TrimSpace(appKey) == "" {
407 return storedCredential{}, appKeyRequiredErrorWithDetails("saved credentials cannot be refreshed without a Dropbox app key", map[string]any{
408 "token_type": authTokenTypeName(tokType),
409 })
410 }
411
412 token, err := refreshOAuthToken(currentContext(), oauthConfigWithAppKey(appKey, domain), credential.oauthToken())
413 if err != nil {
414 return storedCredential{}, err
415 }
416 if token == nil || token.AccessToken == "" {
417 return storedCredential{}, authRefreshFailedErrorfWithDetails("token refresh did not return an access token", map[string]any{
418 "token_type": authTokenTypeName(tokType),
419 })
420 }
421
422 refreshed := storedCredentialFromOAuthToken(token, appKey)
423 if refreshed.RefreshToken == "" {
424 refreshed.RefreshToken = credential.RefreshToken
425 }
426 if refreshed.TokenType == "" {
427 refreshed.TokenType = credential.TokenType
428 }
429 if refreshed.TokenType == "" {
430 refreshed.TokenType = "Bearer"
431 }
432 return refreshed, nil
433}

Callers 1

getAccessCredentialFunction · 0.85

Calls 8

oauthCredentialsFunction · 0.85
authTokenTypeNameFunction · 0.85
currentContextFunction · 0.85
oauthConfigWithAppKeyFunction · 0.85
oauthTokenMethod · 0.80

Tested by

no test coverage detected