Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/auth
diff options
context:
space:
mode:
authorJacob Vosmaer (GitLab) <jacob@gitlab.com>2017-06-20 17:57:16 +0300
committerAndrew Newdigate <andrew@gitlab.com>2017-06-20 17:57:16 +0300
commit74253bf01d5516b9895b4d94a2db1e2db4b58e13 (patch)
tree8e145e4525319e627b53932edc5c9506c2391987 /auth
parentc551b4fe0b8e706772aeb338286e01eec510a719 (diff)
Token authentication
Diffstat (limited to 'auth')
-rw-r--r--auth/rpccredentials.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/auth/rpccredentials.go b/auth/rpccredentials.go
new file mode 100644
index 000000000..cbe94c253
--- /dev/null
+++ b/auth/rpccredentials.go
@@ -0,0 +1,25 @@
+package gitalyauth
+
+import (
+ "encoding/base64"
+
+ "golang.org/x/net/context"
+ "google.golang.org/grpc/credentials"
+)
+
+// RPCCredentials can be used with grpc.WithPerRPCCredentials to create a
+// grpc.DialOption that inserts the supplied token for authentication
+// with a Gitaly server.
+func RPCCredentials(token string) credentials.PerRPCCredentials {
+ return &rpcCredentials{token: base64.StdEncoding.EncodeToString([]byte(token))}
+}
+
+type rpcCredentials struct {
+ token string
+}
+
+func (*rpcCredentials) RequireTransportSecurity() bool { return false }
+
+func (rc *rpcCredentials) GetRequestMetadata(context.Context, ...string) (map[string]string, error) {
+ return map[string]string{"authorization": "Bearer " + rc.token}, nil
+}