Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Add AuthMethod based on HTTP Authorization header #504

Merged
merged 2 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plumbing/revlist/revlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ func Objects(
seen := hashListToSet(ignore)
result := make(map[plumbing.Hash]bool)

cleanerFunc := func(h plumbing.Hash) {
seen[h] = true
}

for _, h := range ignore {
processObject(s, h, hashListToSet([]plumbing.Hash{}), cleanerFunc)
}

walkerFunc := func(h plumbing.Hash) {
if !seen[h] {
result[h] = true
Expand Down
28 changes: 28 additions & 0 deletions plumbing/transport/http/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,34 @@ type AuthMethod interface {
setAuth(r *http.Request)
}

// TokenAuthMethod is concrete implementation of common.AuthMethod for HTTP services
// Allow Bearer Token used in git authentication.
type TokenAuth struct {
token string
}

// NewTokenAuth returns a tokenAuth on the given authrorization token.
func NewTokenAuth(token string) *TokenAuth {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be called it NewBearerAuth ?

return &TokenAuth{token}
}

func (a *TokenAuth) setAuth(r *http.Request) {
if a == nil {
return
}

r.Header.Set("Authorization", a.token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be Bearer requires the format: " Authorization: Bearer %s"

}

// Name is name of the auth
func (a *TokenAuth) Name() string {
return "http-token-auth"
}

func (a *TokenAuth) String() string {
return fmt.Sprintf("%s...", a.token[:10])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The token should be cloaked, otherwise the security can be compromised.

}

func basicAuthFromEndpoint(ep transport.Endpoint) *BasicAuth {
u := ep.User()
if u == "" {
Expand Down