| 321 | } |
| 322 | |
| 323 | func tokenInfoFromResponse(respBody []byte) (*tokenInfo, error) { |
| 324 | respData := &responseParameters{} |
| 325 | if err := json.Unmarshal(respBody, respData); err != nil { |
| 326 | return nil, fmt.Errorf("json.Unmarshal(%v): %v", respBody, err) |
| 327 | } |
| 328 | if respData.AccessToken == "" { |
| 329 | return nil, fmt.Errorf("empty accessToken in response (%v)", string(respBody)) |
| 330 | } |
| 331 | return &tokenInfo{ |
| 332 | tokenType: respData.TokenType, |
| 333 | token: respData.AccessToken, |
| 334 | expiryTime: time.Now().Add(time.Duration(respData.ExpiresIn) * time.Second), |
| 335 | }, nil |
| 336 | } |
| 337 | |
| 338 | // requestParameters stores all STS request attributes defined in |
| 339 | // https://tools.ietf.org/html/rfc8693#section-2.1. |