Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Refactoring access token from sha1 to sha1+JWT #115

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
16 changes: 15 additions & 1 deletion gitea/user_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type AccessToken struct {
ID int64 `json:"id"`
Name string `json:"name"`
Sha1 string `json:"sha1"`
Content string `json:"content,omitempty"`
}

// AccessTokenList represents a list of API access token.
Expand All @@ -40,6 +41,17 @@ func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
// swagger:parameters userCreateToken
type CreateAccessTokenOption struct {
Name string `json:"name" binding:"Required"`
MatchOwner []string `json:"match_owner,omitempty"`
MatchRepo []string `json:"match_repo,omitempty"`
RegexMatchBranch []string `json:"regex_match_branch,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Although regex is more powerful for ease of use I would prefer wildcard match:
https://golang.org/pkg/path/filepath/#Match

Copy link
Author

Choose a reason for hiding this comment

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

thanks and agree. regex was the word came to my mind but actually I meant wildcard.

RegexMatchRoute []string `json:"regex_match_route,omitempty"`
MatchMethod []string `json:"match_method,omitempty"`
Expires int64 `json:"expires,omitempty"`
// allow integrated server app to authenticate by pre-generated token
// and to deprecate basic auth by username and password.
// this will also give server app the option to generate user access token
// on the fly without storing token.
GiteaServerAccessToken string `json:"-"`
}

// CreateAccessToken create one access token with options
Expand All @@ -52,7 +64,9 @@ func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOptio
return t, c.getParsedResponse("POST", fmt.Sprintf("/users/%s/tokens", user),
http.Header{
"content-type": []string{"application/json"},
"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}},
"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)},
"X-Gitea-Server-Access-Token": []string{opt.GiteaServerAccessToken},
},
bytes.NewReader(body), t)
}

Expand Down