/
credential.go
53 lines (43 loc) · 1.88 KB
/
credential.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
52
53
// +build go1.13
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package azcore
import (
"context"
"time"
)
// AuthenticationPolicyOptions contains various options used to create a credential policy.
type AuthenticationPolicyOptions struct {
// Options contains the TokenRequestOptions that includes a scopes field which contains
// the list of OAuth2 authentication scopes used when requesting a token.
// This field is ignored for other forms of authentication (e.g. shared key).
Options TokenRequestOptions
}
// Credential represents any credential type.
type Credential interface {
// AuthenticationPolicy returns a policy that requests the credential and applies it to the HTTP request.
AuthenticationPolicy(options AuthenticationPolicyOptions) Policy
}
// credentialFunc is a type that implements the Credential interface.
// Use this type when implementing a stateless credential as a first-class function.
type credentialFunc func(options AuthenticationPolicyOptions) Policy
// AuthenticationPolicy implements the Credential interface on credentialFunc.
func (cf credentialFunc) AuthenticationPolicy(options AuthenticationPolicyOptions) Policy {
return cf(options)
}
// TokenCredential represents a credential capable of providing an OAuth token.
type TokenCredential interface {
Credential
// GetToken requests an access token for the specified set of scopes.
GetToken(ctx context.Context, options TokenRequestOptions) (*AccessToken, error)
}
// AccessToken represents an Azure service bearer access token with expiry information.
type AccessToken struct {
Token string
ExpiresOn time.Time
}
// TokenRequestOptions contain specific parameter that may be used by credentials types when attempting to get a token.
type TokenRequestOptions struct {
// Scopes contains the list of permission scopes required for the token.
Scopes []string
}