aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/google/s2a-go/internal/tokenmanager
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-07-25 07:50:36 +0000
committerTaras Madan <tarasmadan@google.com>2023-07-25 08:27:48 +0000
commitb423bd03401d00e754d5e5c0236feda4dfb02e28 (patch)
treeb4c5cb53485b00adb2877b7fa27b9b6e5f02552a /vendor/github.com/google/s2a-go/internal/tokenmanager
parente06c669f49a06146914b04a1fbbdd21a0bf1d7b1 (diff)
mod: do: bump golang.org/x/oauth2 from 0.5.0 to 0.10.0
Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.5.0 to 0.10.0. - [Commits](https://github.com/golang/oauth2/compare/v0.5.0...v0.10.0) --- updated-dependencies: - dependency-name: golang.org/x/oauth2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/google/s2a-go/internal/tokenmanager')
-rw-r--r--vendor/github.com/google/s2a-go/internal/tokenmanager/tokenmanager.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/github.com/google/s2a-go/internal/tokenmanager/tokenmanager.go b/vendor/github.com/google/s2a-go/internal/tokenmanager/tokenmanager.go
new file mode 100644
index 000000000..ec96ba3b6
--- /dev/null
+++ b/vendor/github.com/google/s2a-go/internal/tokenmanager/tokenmanager.go
@@ -0,0 +1,70 @@
+/*
+ *
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// Package tokenmanager provides tokens for authenticating to S2A.
+package tokenmanager
+
+import (
+ "fmt"
+ "os"
+
+ commonpb "github.com/google/s2a-go/internal/proto/common_go_proto"
+)
+
+const (
+ s2aAccessTokenEnvironmentVariable = "S2A_ACCESS_TOKEN"
+)
+
+// AccessTokenManager manages tokens for authenticating to S2A.
+type AccessTokenManager interface {
+ // DefaultToken returns a token that an application with no specified local
+ // identity must use to authenticate to S2A.
+ DefaultToken() (token string, err error)
+ // Token returns a token that an application with local identity equal to
+ // identity must use to authenticate to S2A.
+ Token(identity *commonpb.Identity) (token string, err error)
+}
+
+type singleTokenAccessTokenManager struct {
+ token string
+}
+
+// NewSingleTokenAccessTokenManager returns a new AccessTokenManager instance
+// that will always manage the same token.
+//
+// The token to be managed is read from the s2aAccessTokenEnvironmentVariable
+// environment variable. If this environment variable is not set, then this
+// function returns an error.
+func NewSingleTokenAccessTokenManager() (AccessTokenManager, error) {
+ token, variableExists := os.LookupEnv(s2aAccessTokenEnvironmentVariable)
+ if !variableExists {
+ return nil, fmt.Errorf("%s environment variable is not set", s2aAccessTokenEnvironmentVariable)
+ }
+ return &singleTokenAccessTokenManager{token: token}, nil
+}
+
+// DefaultToken always returns the token managed by the
+// singleTokenAccessTokenManager.
+func (m *singleTokenAccessTokenManager) DefaultToken() (string, error) {
+ return m.token, nil
+}
+
+// Token always returns the token managed by the singleTokenAccessTokenManager.
+func (m *singleTokenAccessTokenManager) Token(*commonpb.Identity) (string, error) {
+ return m.token, nil
+}