@@ -118,6 +118,8 @@ var defaultAzdTokenProvider PSTokenProvider = func(ctx context.Context, _ string
118
118
defer cancel ()
119
119
}
120
120
121
+ r := regexp .MustCompile ("(?s){.*Token.*ExpiresOn.*}" )
122
+
121
123
if tenantID != "" {
122
124
tenantID += " -TenantId" + tenantID
123
125
}
@@ -138,8 +140,9 @@ var defaultAzdTokenProvider PSTokenProvider = func(ctx context.Context, _ string
138
140
return nil , errors .New (credNamePSContext + msg )
139
141
}
140
142
141
- if ! strings .Contains (string (output ), "Token" ) || ! strings .Contains (string (output ), "ExpiresOn" ) {
142
- invalidTokenMsg := " Invalid output received while retriving token with Powershell. Run command \" + cmd + \" " +
143
+ output = []byte (r .FindString (string (output )))
144
+ if string (output ) == "" {
145
+ invalidTokenMsg := " Invalid output received while retrieving token with Powershell. Run command \" " + cmd + "\" " +
143
146
" on powershell and verify that the output is indeed a valid token."
144
147
return nil , errors .New (credNamePSContext + invalidTokenMsg )
145
148
}
@@ -152,9 +155,9 @@ func (c *PowershellContextCredential) createAccessToken(tk []byte) (azcore.Acces
152
155
ExpiresOn string `json:"ExpiresOn"`
153
156
}{}
154
157
155
- err := json .Unmarshal (tk , & t )
158
+ err := json .Unmarshal ([] byte ( strings . TrimSpace ( string ( tk ))) , & t )
156
159
if err != nil {
157
- return azcore.AccessToken {}, errors .New (err .Error ())
160
+ return azcore.AccessToken {}, errors .New (err .Error () + string ( tk ) )
158
161
}
159
162
160
163
parseErr := "error parsing token expiration time %q: %v"
0 commit comments