@@ -136,8 +136,12 @@ const (
136136const (
137137 AAD = "MSSTS"
138138 ADFS = "ADFS"
139+ DSTS = "DSTS"
139140)
140141
142+ // DSTSTenant is referenced throughout multiple files, let us use a const in case we ever need to change it.
143+ const DSTSTenant = "7a433bfc-2514-4697-b467-e0933190487f"
144+
141145// AuthenticationScheme is an extensibility mechanism designed to be used only by Azure Arc for proof of possession access tokens.
142146type AuthenticationScheme interface {
143147 // Extra parameters that are added to the request to the /token endpoint.
@@ -251,6 +255,8 @@ func (p AuthParams) WithTenant(ID string) (AuthParams, error) {
251255 authority = "https://" + path .Join (p .AuthorityInfo .Host , ID )
252256 case ADFS :
253257 return p , errors .New ("ADFS authority doesn't support tenants" )
258+ case DSTS :
259+ return p , errors .New ("dSTS authority doesn't support tenants" )
254260 }
255261
256262 info , err := NewInfoFromAuthorityURI (authority , p .AuthorityInfo .ValidateAuthority , p .AuthorityInfo .InstanceDiscoveryDisabled )
@@ -350,35 +356,43 @@ type Info struct {
350356 InstanceDiscoveryDisabled bool
351357}
352358
353- func firstPathSegment (u * url.URL ) (string , error ) {
354- pathParts := strings .Split (u .EscapedPath (), "/" )
355- if len (pathParts ) >= 2 {
356- return pathParts [1 ], nil
357- }
358-
359- return "" , errors .New (`authority must be an https URL such as "https://login.microsoftonline.com/<your tenant>"` )
360- }
361-
362359// NewInfoFromAuthorityURI creates an AuthorityInfo instance from the authority URL provided.
363360func NewInfoFromAuthorityURI (authority string , validateAuthority bool , instanceDiscoveryDisabled bool ) (Info , error ) {
364361 u , err := url .Parse (strings .ToLower (authority ))
365- if err != nil || u .Scheme != "https" {
366- return Info {}, errors .New (`authority must be an https URL such as "https://login.microsoftonline.com/<your tenant>"` )
362+ if err != nil {
363+ return Info {}, fmt .Errorf ("couldn't parse authority url: %w" , err )
364+ }
365+ if u .Scheme != "https" {
366+ return Info {}, errors .New ("authority url scheme must be https" )
367367 }
368368
369- tenant , err := firstPathSegment ( u )
370- if err != nil {
371- return Info {}, err
369+ pathParts := strings . Split ( u . EscapedPath (), "/" )
370+ if len ( pathParts ) < 2 {
371+ return Info {}, errors . New ( `authority must be an URL such as "https://login.microsoftonline.com/<your tenant>"` )
372372 }
373- authorityType := AAD
374- if tenant == "adfs" {
373+
374+ var authorityType , tenant string
375+ switch pathParts [1 ] {
376+ case "adfs" :
375377 authorityType = ADFS
378+ case "dstsv2" :
379+ if len (pathParts ) != 3 {
380+ return Info {}, fmt .Errorf ("dSTS authority must be an https URL such as https://<authority>/dstsv2/%s" , DSTSTenant )
381+ }
382+ if pathParts [2 ] != DSTSTenant {
383+ return Info {}, fmt .Errorf ("dSTS authority only accepts a single tenant %q" , DSTSTenant )
384+ }
385+ authorityType = DSTS
386+ tenant = DSTSTenant
387+ default :
388+ authorityType = AAD
389+ tenant = pathParts [1 ]
376390 }
377391
378392 // u.Host includes the port, if any, which is required for private cloud deployments
379393 return Info {
380394 Host : u .Host ,
381- CanonicalAuthorityURI : fmt . Sprintf ( "https://%v/%v/" , u . Host , tenant ) ,
395+ CanonicalAuthorityURI : authority ,
382396 AuthorityType : authorityType ,
383397 ValidateAuthority : validateAuthority ,
384398 Tenant : tenant ,
0 commit comments