From 8eb68ba817dff8eb268cc884c78a384cbf0e3ce5 Mon Sep 17 00:00:00 2001 From: Gucheng Wang Date: Fri, 31 Mar 2023 19:24:03 +0800 Subject: [PATCH] fix: fix AAD single-tenant mode bug --- idp/goth.go | 9 +++++++-- idp/provider.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/idp/goth.go b/idp/goth.go index f162b9b5..b3c4849b 100644 --- a/idp/goth.go +++ b/idp/goth.go @@ -88,7 +88,7 @@ type GothIdProvider struct { Session goth.Session } -func NewGothIdProvider(providerType string, clientId string, clientSecret string, redirectUrl string) *GothIdProvider { +func NewGothIdProvider(providerType string, clientId string, clientSecret string, redirectUrl string, hostUrl string) *GothIdProvider { var idp GothIdProvider switch providerType { case "Amazon": @@ -102,8 +102,13 @@ func NewGothIdProvider(providerType string, clientId string, clientSecret string Session: &apple.Session{}, } case "AzureAD": + domain := "common" + if hostUrl != "" { + domain = hostUrl + } + idp = GothIdProvider{ - Provider: azureadv2.New(clientId, clientSecret, redirectUrl, azureadv2.ProviderOptions{Tenant: "common"}), + Provider: azureadv2.New(clientId, clientSecret, redirectUrl, azureadv2.ProviderOptions{Tenant: azureadv2.TenantType(domain)}), Session: &azureadv2.Session{}, } case "Auth0": diff --git a/idp/provider.go b/idp/provider.go index 3e50259e..d96de0f2 100644 --- a/idp/provider.go +++ b/idp/provider.go @@ -90,7 +90,7 @@ func GetIdProvider(typ string, subType string, clientId string, clientSecret str } else if typ == "Douyin" { return NewDouyinIdProvider(clientId, clientSecret, redirectUrl) } else if isGothSupport(typ) { - return NewGothIdProvider(typ, clientId, clientSecret, redirectUrl) + return NewGothIdProvider(typ, clientId, clientSecret, redirectUrl, hostUrl) } else if typ == "Bilibili" { return NewBilibiliIdProvider(clientId, clientSecret, redirectUrl) }