Skip to content

Commit

Permalink
fix hcp jwt parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
David Corrigan committed Apr 4, 2023
1 parent 8269c4b commit fdc45f2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion azuredevops/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,15 @@ func getAuthToken(ctx context.Context, d *schema.ResourceData) (string, error) {
tenantIdApply := d.Get("sp_tenant_id_apply").(string)

workloadIdentityTokenUnmarshalled := HCPWorkloadToken{}
err := json.Unmarshal([]byte(workloadIdentityToken), &workloadIdentityTokenUnmarshalled)
jwtParts := strings.Split(workloadIdentityToken, ".")
if len(jwtParts) != 3 {
return "", errors.New("Unable to split TFC_WORKLOAD_IDENTITY_TOKEN JWT")
}
tokenClaims, err := base64.StdEncoding.DecodeString(jwtParts[1])
if err != nil {
return "", err
}
err = json.Unmarshal(tokenClaims, &workloadIdentityTokenUnmarshalled)
if err != nil {
return "", err
}
Expand Down

0 comments on commit fdc45f2

Please sign in to comment.