1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions"
8
"github.com/Azure/go-autorest/autorest/azure"
9
"github.com/juju/errors"
12
// OAuthConfig returns an azure.OAuthConfig based on the given resource
13
// manager endpoint and subscription ID. This will make a request to the
14
// resource manager API to discover the Active Directory tenant ID.
16
client subscriptions.Client,
17
resourceManagerEndpoint string,
18
subscriptionId string,
19
) (*azure.OAuthConfig, string, error) {
20
authURI, err := DiscoverAuthorizationURI(client, subscriptionId)
22
return nil, "", errors.Annotate(err, "detecting auth URI")
24
logger.Debugf("discovered auth URI: %s", authURI)
26
// The authorization URI scheme and host identifies the AD endpoint.
27
// The authorization URI path identifies the AD tenant.
28
tenantId, err := AuthorizationURITenantID(authURI)
30
return nil, "", errors.Annotate(err, "getting tenant ID")
33
adEndpoint := authURI.String()
35
cloudEnv := azure.Environment{ActiveDirectoryEndpoint: adEndpoint}
36
oauthConfig, err := cloudEnv.OAuthConfigForTenant(tenantId)
38
return nil, "", errors.Annotate(err, "getting OAuth configuration")
40
return oauthConfig, tenantId, nil