MCPcopy Create free account
hub / github.com/cloudfoundry/cli / RefreshAccessToken

Method RefreshAccessToken

api/uaa/refresh_token.go:26–62  ·  view source on GitHub ↗

RefreshAccessToken refreshes the current access token.

(refreshToken string)

Source from the content-addressed store, hash-verified

24
25// RefreshAccessToken refreshes the current access token.
26func (client *Client) RefreshAccessToken(refreshToken string) (RefreshedTokens, error) {
27 var values url.Values
28
29 switch client.config.UAAGrantType() {
30 case string(constant.GrantTypeClientCredentials):
31 values = client.clientCredentialRefreshBody()
32 case "", string(constant.GrantTypePassword), string(constant.GrantTypeJwtBearer): // CLI used to write empty string for grant type in the case of password; preserve compatibility with old config.json files
33 values = client.refreshTokenBody(refreshToken)
34 }
35
36 body := strings.NewReader(values.Encode())
37
38 request, err := client.newRequest(requestOptions{
39 RequestName: internal.PostOAuthTokenRequest,
40 Header: http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
41 Body: body,
42 })
43 if err != nil {
44 return RefreshedTokens{}, err
45 }
46
47 if client.config.UAAGrantType() != string(constant.GrantTypeClientCredentials) {
48 request.SetBasicAuth(client.config.UAAOAuthClient(), client.config.UAAOAuthClientSecret())
49 }
50
51 var refreshResponse RefreshedTokens
52 response := Response{
53 Result: &refreshResponse,
54 }
55
56 err = client.connection.Make(request, &response)
57 if err != nil {
58 return RefreshedTokens{}, err
59 }
60
61 return refreshResponse, nil
62}
63
64func (client *Client) clientCredentialRefreshBody() url.Values {
65 return url.Values{

Callers

nothing calls this directly

Calls 7

refreshTokenBodyMethod · 0.95
newRequestMethod · 0.95
UAAGrantTypeMethod · 0.65
UAAOAuthClientMethod · 0.65
UAAOAuthClientSecretMethod · 0.65
MakeMethod · 0.65

Tested by

no test coverage detected