Skip to content

Commit

Permalink
auth: nil checks in Token() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
manicminer committed Oct 13, 2021
1 parent dfb8aa9 commit 781f6c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion auth/azcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ type AzureCliAuthorizer struct {
}

// Token returns an access token using the Azure CLI as an authentication mechanism.
func (a AzureCliAuthorizer) Token() (*oauth2.Token, error) {
func (a *AzureCliAuthorizer) Token() (*oauth2.Token, error) {
if a.conf == nil {
return nil, fmt.Errorf("could not request token: conf is nil")
}

var token struct {
AccessToken string `json:"accessToken"`
ExpiresOn string `json:"expiresOn"`
Expand Down
12 changes: 10 additions & 2 deletions auth/clientcredentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ type clientAssertionAuthorizer struct {
conf *ClientCredentialsConfig
}

func (a clientAssertionAuthorizer) Token() (*oauth2.Token, error) {
func (a *clientAssertionAuthorizer) Token() (*oauth2.Token, error) {
if a.conf == nil {
return nil, fmt.Errorf("could not request token: conf is nil")
}

crt := a.conf.Certificate
if der, _ := pem.Decode(a.conf.Certificate); der != nil {
crt = der.Bytes
Expand Down Expand Up @@ -246,7 +250,11 @@ type clientSecretAuthorizer struct {
conf *ClientCredentialsConfig
}

func (a clientSecretAuthorizer) Token() (*oauth2.Token, error) {
func (a *clientSecretAuthorizer) Token() (*oauth2.Token, error) {
if a.conf == nil {
return nil, fmt.Errorf("could not request token: conf is nil")
}

v := url.Values{
"client_id": {a.conf.ClientID},
"client_secret": {a.conf.ClientSecret},
Expand Down
4 changes: 4 additions & 0 deletions auth/msi.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type MsiAuthorizer struct {

// Token returns an access token acquired from the metadata endpoint.
func (a *MsiAuthorizer) Token() (*oauth2.Token, error) {
if a.conf == nil {
return nil, fmt.Errorf("could not request token: conf is nil")
}

query := url.Values{
"api-version": []string{a.conf.MsiApiVersion},
"resource": []string{a.conf.Resource},
Expand Down

0 comments on commit 781f6c0

Please sign in to comment.