@@ -98,27 +98,33 @@ func (a *AzurePipelinesCredential) getAssertion(ctx context.Context) (string, er
9898 url := a .oidcURI + "?api-version=" + oidcAPIVersion + "&serviceConnectionId=" + a .connectionID
9999 url , err := runtime .EncodeQueryParams (url )
100100 if err != nil {
101- return "" , err
101+ return "" , newAuthenticationFailedError ( credNameAzurePipelines , "couldn't encode OIDC URL: " + err . Error (), nil , nil )
102102 }
103103 req , err := http .NewRequestWithContext (ctx , http .MethodPost , url , nil )
104104 if err != nil {
105- return "" , err
105+ return "" , newAuthenticationFailedError ( credNameAzurePipelines , "couldn't create OIDC token request: " + err . Error (), nil , nil )
106106 }
107107 req .Header .Set ("Authorization" , "Bearer " + a .systemAccessToken )
108108 res , err := doForClient (a .cred .client .azClient , req )
109109 if err != nil {
110- return "" , err
110+ return "" , newAuthenticationFailedError (credNameAzurePipelines , "couldn't send OIDC token request: " + err .Error (), nil , nil )
111+ }
112+ if res .StatusCode != http .StatusOK {
113+ msg := res .Status + " response from the OIDC endpoint. Check service connection ID and Pipeline configuration"
114+ // include the response because its body, if any, probably contains an error message.
115+ // OK responses aren't included with errors because they probably contain secrets
116+ return "" , newAuthenticationFailedError (credNameAzurePipelines , msg , res , nil )
111117 }
112118 b , err := runtime .Payload (res )
113119 if err != nil {
114- return "" , err
120+ return "" , newAuthenticationFailedError ( credNameAzurePipelines , "couldn't read OIDC response content: " + err . Error (), nil , nil )
115121 }
116122 var r struct {
117123 OIDCToken string `json:"oidcToken"`
118124 }
119125 err = json .Unmarshal (b , & r )
120126 if err != nil {
121- return "" , err
127+ return "" , newAuthenticationFailedError ( credNameAzurePipelines , "unexpected response from OIDC endpoint" , nil , nil )
122128 }
123129 return r .OIDCToken , nil
124130}
0 commit comments