Skip to content

hard code oauth app git-credential-oauth #25774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 19 additions & 0 deletions models/auth/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ func (app *OAuth2Application) CreateGrant(ctx context.Context, userID int64, sco

// GetOAuth2ApplicationByClientID returns the oauth2 application with the given client_id. Returns an error if not found.
func GetOAuth2ApplicationByClientID(ctx context.Context, clientID string) (app *OAuth2Application, err error) {
// the following Git credential helpers are universally useful
// https://git-scm.com/doc/credential-helpers
if clientID == "a4792ccc-144e-407e-86c9-5e7d8d9c3269" {
return &OAuth2Application{
Name: "git-credential-oauth",
ClientID: "a4792ccc-144e-407e-86c9-5e7d8d9c3269",
ConfidentialClient: false,
RedirectURIs: []string{"http://127.0.0.1"},
}, nil
}
if clientID == "e90ee53c-94e2-48ac-9358-a874fb9e0662" {
return &OAuth2Application{
Name: "Git Credential Manager",
ClientID: "e90ee53c-94e2-48ac-9358-a874fb9e0662",
ConfidentialClient: false,
RedirectURIs: []string{"http://127.0.0.1"},
}, nil
}

app = new(OAuth2Application)
has, err := db.GetEngine(ctx).Where("client_id = ?", clientID).Get(app)
if !has {
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func httpBase(ctx *context.Context) *serviceHandler {
// rely on the results of Contexter
if !ctx.IsSigned {
// TODO: support digit auth - which would be Authorization header with digit
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`)
ctx.Error(http.StatusUnauthorized)
return nil
}
Expand Down