@@ -23,49 +23,84 @@ type AzureProvider struct {
24var _ Provider = (*AzureProvider)(nil)
24var _ Provider = (*AzureProvider)(nil)
27+ azureProviderName = "Azure"
28+ azureDefaultScope = "openid"
32+ // Default Login URL for Azure.
33+ // Pre-parsed URL of https://login.microsoftonline.com/common/oauth2/authorize.
34+ azureDefaultLoginURL = &url.URL{
36+ Host: "login.microsoftonline.com",
37+ Path: "/common/oauth2/authorize",
40+ // Default Redeem URL for Azure.
41+ // Pre-parsed URL of https://login.microsoftonline.com/common/oauth2/token.
42+ azureDefaultRedeemURL = &url.URL{
44+ Host: "login.microsoftonline.com",
45+ Path: "/common/oauth2/token",
48+ // Default Profile URL for Azure.
49+ // Pre-parsed URL of https://graph.microsoft.com/v1.0/me.
50+ azureDefaultProfileURL = &url.URL{
52+ Host: "graph.microsoft.com",
56+ // Default ProtectedResource URL for Azure.
57+ // Pre-parsed URL of https://graph.microsoft.com.
58+ azureDefaultProtectResourceURL = &url.URL{
60+ Host: "graph.microsoft.com",
26// NewAzureProvider initiates a new AzureProvider
64// NewAzureProvider initiates a new AzureProvider
27func NewAzureProvider(p *ProviderData) *AzureProvider {
65func NewAzureProvider(p *ProviderData) *AzureProvider {
28− p.ProviderName = "Azure"
66+ p.setProviderDefaults(providerDefaults{
67+ name: azureProviderName,
68+ loginURL: azureDefaultLoginURL,
69+ redeemURL: azureDefaultRedeemURL,
70+ profileURL: azureDefaultProfileURL,
72+ scope: azureDefaultScope,
30− if p.ProfileURL == nil || p.ProfileURL.String() == "" {
31− p.ProfileURL = &url.URL{
33− Host: "graph.microsoft.com",
37 if p.ProtectedResource == nil || p.ProtectedResource.String() == "" {
75 if p.ProtectedResource == nil || p.ProtectedResource.String() == "" {
38− p.ProtectedResource = &url.URL{
76+ p.ProtectedResource = azureDefaultProtectResourceURL
40− Host: "graph.microsoft.com",
47− return &AzureProvider{ProviderData: p}
79+ return &AzureProvider{
50// Configure defaults the AzureProvider configuration options
85// Configure defaults the AzureProvider configuration options
51func (p *AzureProvider) Configure(tenant string) {
86func (p *AzureProvider) Configure(tenant string) {
53− if tenant == "" {
87+ if tenant == "" || tenant == "common" {
54− p.Tenant = "common"
88+ // tenant is empty or default, remain on the default "common" tenant
57− if p.LoginURL == nil || p.LoginURL.String() == "" {
92+ // Specific tennant specified, override the Login and RedeemURLs
58− p.LoginURL = &url.URL{
93+ p.Tenant = tenant
59− Scheme: "https",
94+ overrideTenantURL(p.LoginURL, azureDefaultLoginURL, tenant, "authorize")
60− Host: "login.microsoftonline.com",
95+ overrideTenantURL(p.RedeemURL, azureDefaultRedeemURL, tenant, "token")
61− Path: "/" + p.Tenant + "/oauth2/authorize"}
63− if p.RedeemURL == nil || p.RedeemURL.String() == "" {
97+
98+func overrideTenantURL(current, defaultURL *url.URL, tenant, path string) {
99+ if current == nil || current.String() == "" || current.String() == defaultURL.String() {
64− p.RedeemURL = &url.URL{
100+ *current = url.URL{
65 Scheme: "https",
101 Scheme: "https",
66 Host: "login.microsoftonline.com",
102 Host: "login.microsoftonline.com",
67− Path: "/" + p.Tenant + "/oauth2/token",
103+ Path: "/" + tenant + "/oauth2/" + path}