Created
May 18, 2019 05:44
-
-
Save DexterPOSH/cb9a69a7c0ff07593e40eae5e1728cee to your computer and use it in GitHub Desktop.
getAuthorizer() method for settings struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (settings settings) getAuthorizer() (autorest.Authorizer, error) { | |
//1.Client Credentials | |
if settings.clientSecret != "" { | |
config := NewClientCredentialsConfig(settings.clientID, settings.clientSecret, settings.tenantID) | |
config.AADEndpoint = settings.environment.ActiveDirectoryEndpoint | |
config.Resource = settings.resource | |
return config.Authorizer() | |
} | |
//2. Client Certificate | |
if settings.certificatePath != "" { | |
config := NewClientCertificateConfig(settings.certificatePath, settings.certificatePassword, settings.clientID, settings.tenantID) | |
config.AADEndpoint = settings.environment.ActiveDirectoryEndpoint | |
config.Resource = settings.resource | |
return config.Authorizer() | |
} | |
//3. Username Password | |
if settings.username != "" && settings.password != "" { | |
config := NewUsernamePasswordConfig(settings.username, settings.password, settings.clientID, settings.tenantID) | |
config.AADEndpoint = settings.environment.ActiveDirectoryEndpoint | |
config.Resource = settings.resource | |
return config.Authorizer() | |
} | |
// 4. MSI | |
config := NewMSIConfig() | |
config.Resource = settings.resource | |
config.ClientID = settings.clientID | |
return config.Authorizer() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment