MCPcopy Index your code
hub / github.com/cloudfoundry/cli / RefreshToken

Method RefreshToken

cf/api/authentication/authentication.go:190–218  ·  view source on GitHub ↗
(t string)

Source from the content-addressed store, hash-verified

188}
189
190func (uaa UAARepository) RefreshToken(t string) (string, error) {
191 tokenStr := strings.TrimPrefix(t, "bearer ")
192 token, err := jws.ParseJWT([]byte(tokenStr))
193 if err != nil {
194 return "", err
195 }
196 expiration, ok := token.Claims().Expiration()
197 if ok && expiration.Sub(time.Now()) > accessTokenExpirationMargin {
198 return t, nil
199 }
200
201 data := url.Values{}
202
203 switch uaa.config.UAAGrantType() {
204 case "client_credentials":
205 data.Add("client_id", uaa.config.UAAOAuthClient())
206 data.Add("client_secret", uaa.config.UAAOAuthClientSecret())
207 data.Add("grant_type", "client_credentials")
208 case "", "password": // CLI used to leave field blank for password; preserve compatibility with old files
209 data.Add("grant_type", "refresh_token")
210 data.Add("refresh_token", uaa.config.RefreshToken())
211 data.Add("scope", "")
212 }
213
214 apiErr := uaa.getAuthToken(data)
215 updatedToken := uaa.config.AccessToken()
216
217 return updatedToken, apiErr
218}
219
220func (uaa UAARepository) getAuthToken(data url.Values) error {
221 var accessToken string

Callers 1

RefreshAuthTokenMethod · 0.95

Calls 8

getAuthTokenMethod · 0.95
NowMethod · 0.65
UAAGrantTypeMethod · 0.65
AddMethod · 0.65
UAAOAuthClientMethod · 0.65
UAAOAuthClientSecretMethod · 0.65
RefreshTokenMethod · 0.65
AccessTokenMethod · 0.65

Tested by

no test coverage detected