diff options
author | Eric Billingsley <eric@calculi.com> | 2018-06-08 15:19:12 -0700 |
---|---|---|
committer | Eric Billingsley <eric@calculi.com> | 2018-06-08 15:19:12 -0700 |
commit | bf6190841e8b6cd3a216bc056e5b71c73e18c410 (patch) | |
tree | 8e5a48002cf8aa1d0cdb4bac838b1af15f34d1e3 /plumbing/transport/http/common.go | |
parent | b23570073eaee3489e5e3d666f22ba5cbeb53243 (diff) | |
download | go-git-bf6190841e8b6cd3a216bc056e5b71c73e18c410.tar.gz |
plumbing/transport: http, Adds token authentication support [Fixes #858]
Signed-off-by: Eric Billingsley <ebilling@babrains.com>
Diffstat (limited to 'plumbing/transport/http/common.go')
-rw-r--r-- | plumbing/transport/http/common.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/plumbing/transport/http/common.go b/plumbing/transport/http/common.go index 2c337b7..c034846 100644 --- a/plumbing/transport/http/common.go +++ b/plumbing/transport/http/common.go @@ -201,6 +201,31 @@ func (a *BasicAuth) String() string { return fmt.Sprintf("%s - %s:%s", a.Name(), a.Username, masked) } +// TokenAuth implements the go-git http.AuthMethod and transport.AuthMethod interfaces +type TokenAuth struct { + Token string +} + +func (a *TokenAuth) setAuth(r *http.Request) { + if a == nil { + return + } + r.Header.Add("Authorization", fmt.Sprintf("Bearer %s", a.Token)) +} + +// Name is name of the auth +func (a *TokenAuth) Name() string { + return "http-token-auth" +} + +func (a *TokenAuth) String() string { + masked := "*******" + if a.Token == "" { + masked = "<empty>" + } + return fmt.Sprintf("%s - %s", a.Name(), masked) +} + // Err is a dedicated error to return errors based on status code type Err struct { Response *http.Response |