@@ -235,23 +235,24 @@ func NewAuthParams(clientID string, authorityInfo Info) AuthParams {
235235// - the client is configured to authenticate only Microsoft accounts via the "consumers" endpoint
236236// - the resulting authority URL is invalid
237237func (p AuthParams ) WithTenant (ID string ) (AuthParams , error ) {
238- switch ID {
239- case "" , p .AuthorityInfo .Tenant :
240- // keep the default tenant because the caller didn't override it
238+ if ID == "" || ID == p .AuthorityInfo .Tenant {
241239 return p , nil
242- case "common" , "consumers" , "organizations" :
243- if p .AuthorityInfo .AuthorityType == AAD {
240+ }
241+
242+ var authority string
243+ switch p .AuthorityInfo .AuthorityType {
244+ case AAD :
245+ if ID == "common" || ID == "consumers" || ID == "organizations" {
244246 return p , fmt .Errorf (`tenant ID must be a specific tenant, not "%s"` , ID )
245247 }
246- // else we'll return a better error below
247- }
248- if p .AuthorityInfo .AuthorityType != AAD {
249- return p , errors .New ("the authority doesn't support tenants" )
250- }
251- if p .AuthorityInfo .Tenant == "consumers" {
252- return p , errors .New (`client is configured to authenticate only personal Microsoft accounts, via the "consumers" endpoint` )
248+ if p .AuthorityInfo .Tenant == "consumers" {
249+ return p , errors .New (`client is configured to authenticate only personal Microsoft accounts, via the "consumers" endpoint` )
250+ }
251+ authority = "https://" + path .Join (p .AuthorityInfo .Host , ID )
252+ case ADFS :
253+ return p , errors .New ("ADFS authority doesn't support tenants" )
253254 }
254- authority := "https://" + path . Join ( p . AuthorityInfo . Host , ID )
255+
255256 info , err := NewInfoFromAuthorityURI (authority , p .AuthorityInfo .ValidateAuthority , p .AuthorityInfo .InstanceDiscoveryDisabled )
256257 if err == nil {
257258 info .Region = p .AuthorityInfo .Region
0 commit comments