-
Notifications
You must be signed in to change notification settings - Fork 46
/
oidc_authorizer.go
51 lines (40 loc) · 1.57 KB
/
oidc_authorizer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package auth
import (
"context"
"fmt"
"github.com/hashicorp/go-azure-sdk/sdk/environments"
)
type OIDCAuthorizerOptions struct {
// Environment is the Azure environment/cloud being targeted
Environment environments.Environment
// Api describes the Azure API being used
Api environments.Api
// TenantId is the tenant to authenticate against
TenantId string
// AuxiliaryTenantIds lists additional tenants to authenticate against, currently only
// used for Resource Manager when auxiliary tenants are needed.
// e.g. https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/authenticate-multi-tenant
AuxiliaryTenantIds []string
// ClientId is the client ID used when authenticating
ClientId string
// FederatedAssertion is the client assertion dispensed by the OIDC provider used to verify identity during authentication
FederatedAssertion string
}
// NewOIDCAuthorizer returns an authorizer which uses OIDC authentication (federated client credentials)
func NewOIDCAuthorizer(ctx context.Context, options OIDCAuthorizerOptions) (Authorizer, error) {
scope, err := environments.Scope(options.Api)
if err != nil {
return nil, fmt.Errorf("determining scope for %q: %+v", options.Api.Name(), err)
}
conf := clientCredentialsConfig{
Environment: options.Environment,
TenantID: options.TenantId,
AuxiliaryTenantIDs: options.AuxiliaryTenantIds,
ClientID: options.ClientId,
FederatedAssertion: options.FederatedAssertion,
Scopes: []string{
*scope,
},
}
return conf.TokenSource(ctx, clientCredentialsAssertionType)
}