RefreshAccessToken refreshes the current access token.
(refreshToken string)
| 24 | |
| 25 | // RefreshAccessToken refreshes the current access token. |
| 26 | func (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 | |
| 64 | func (client *Client) clientCredentialRefreshBody() url.Values { |
| 65 | return url.Values{ |
nothing calls this directly
no test coverage detected