hamilton icon indicating copy to clipboard operation
hamilton copied to clipboard

autorest.BearerAuthorization does not have `Token` method

Open ekristen opened this issue 3 years ago • 6 comments

I'm passing an autorest.BearerAuthorization to the wrappedAuth, err := auth.NewAutorestAuthorizerWrapper(authorizer) method call but it returns could not obtain access token from token provider.

It appears it's trying to find .Token method and failing. The autorest.BearerAuthorization provider only has a OAuthToken method.

Is this a bug or am I using it incorrectly?

Thanks.

ekristen avatar Feb 11 '22 22:02 ekristen

Changing line 47 of auth/autorest.go seems to make it work properly.

                tokenProviders = append(tokenProviders, &servicePrincipalTokenWrapper{
			tokenType:  "Bearer",
			tokenValue: authorizer.TokenProvider().OAuthToken(),
		})

ekristen avatar Feb 12 '22 01:02 ekristen

Hi @ekristen, thanks for reporting this and also your findings! We'll very soon be looking at tidying up the autorest wrapper and will look to incorporate this fix 👍

manicminer avatar Feb 17 '22 04:02 manicminer

@manicminer would you like me to open a PR on this?

ekristen avatar May 18 '22 16:05 ekristen

Hi @ekristen, thanks, a PR would be very much appreciated! 👍

manicminer avatar May 30 '22 08:05 manicminer

https://github.com/manicminer/hamilton-autorest/pull/3 -- as stated on the PR, this could be wrong. The golang docs for azure sdk and the autorest stuff is not very clear IMO, but this makes this work properly for me with the autorest wrapper.

ekristen avatar May 31 '22 02:05 ekristen

could this fix also your issue? https://github.com/manicminer/hamilton-autorest/pull/4

mblaschke avatar Sep 02 '22 08:09 mblaschke