Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ded3513
initial stuff for oauth2 login, fails on:
Jan 10, 2017
1f94c85
login button on the signIn page to start the OAuth2 flow and a callba…
Jan 15, 2017
642f36e
Merge branch 'upstream-master' into oauth2-consumer
Jan 15, 2017
f93aad8
fix indentation
Jan 16, 2017
280913b
prevent macaron.Context in models
Jan 16, 2017
b597a86
show login button only when the OAuth2 consumer is configured (and ac…
Jan 16, 2017
8c2be7a
move overrides of goth functions to init
Jan 16, 2017
f392ce9
Merge remote-tracking branch 'upstream/master' into oauth2-consumer
Jan 16, 2017
2ba7833
create macaron group for oauth2 urls
Jan 16, 2017
8e1ea96
fix the broken url (dubble oauth2)
Jan 16, 2017
6c98fa7
no support at this moment to use this and we should only consider imp…
Jan 17, 2017
caeb911
prevent net/http in modules (other then oauth2)
Jan 23, 2017
f3f3866
use a new data sessions oauth2 folder for storing the oauth2 session …
Jan 23, 2017
047d50b
update resolving, naming and security settings of sessions oauth2 dir…
Jan 23, 2017
ab31c24
add missing 2FA when this is enabled on the user
Jan 23, 2017
fe88e87
add password option for OAuth2 user , for use with git over http and …
Jan 24, 2017
827c512
Merge remote-tracking branch 'upstream/master' into oauth2-consumer
Jan 25, 2017
83c238b
merge vendor.json incl goth library
Jan 25, 2017
c65a216
set a default provider instead of a empty option
Jan 25, 2017
914f56a
add tip for registering a GitHub OAuth application
Jan 25, 2017
b4eb93c
remove unused redirectURL
Jan 26, 2017
7a6757f
at startup of Gitea register all configured providers and also on add…
Jan 27, 2017
aae5f80
always use source.Name as provider key
Jan 27, 2017
9151dc8
custom handling of errors in oauth2 request init + show better tip
Jan 27, 2017
96d1af5
more checks if provider exists and is active (less calls to db to che…
Jan 27, 2017
c3f5d36
add ExternalLoginUser model and migration script to add it to database
Jan 27, 2017
2bf6b34
remove unused IsSocialLogin code
Jan 27, 2017
7ccbc44
create initial flow for linkAccount, todo: handle the POST of LinkAcc…
Jan 27, 2017
084c45f
link a external account to an existing account (still need to handle …
Jan 27, 2017
6594d76
remove the linked external account from the user his settings
Jan 30, 2017
19ddb15
make clear why we don't do anything here
Jan 30, 2017
57dbb74
add license header
Jan 30, 2017
32a4c58
if user is unknown we allow him to register a new account or link it …
Jan 31, 2017
770ba31
we are in 2017...
Jan 31, 2017
527d6e1
sign up with button on signin page (als change OAuth2Provider structu…
Feb 2, 2017
a7381b5
prevent panic when non-existing provider is in database or cannot be …
Feb 2, 2017
b64ee7d
fix err check so update of source is working
Feb 2, 2017
5c5214a
Merge remote-tracking branch 'upstream/master' into oauth2-consumer
Feb 5, 2017
769c747
merge master forces update of database to newer version
Feb 5, 2017
6b16f42
from gorilla/sessions docs:
Feb 6, 2017
0fa2e40
fix missed password reset
Feb 8, 2017
f54f07a
use updated goth lib that now supports getting the OAuth2 user if the…
Feb 8, 2017
873e5b7
Merge branch 'upstream-master' into oauth2-consumer
Feb 8, 2017
779e84b
manual merge the changes in signup.tmpl to signup_inner.tmpl
Feb 8, 2017
61fe261
prepare merge
Feb 21, 2017
66e28df
Merge branch 'upstream-master' into oauth2-consumer
Feb 21, 2017
2c11c44
Merge branch 'oauth2-consumer' of github.com:willemvd/gitea into oaut…
Feb 21, 2017
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
9 changes: 5 additions & 4 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/go-macaron/toolbox"
"github.com/urfave/cli"
macaron "gopkg.in/macaron.v1"
context2 "github.com/gorilla/context"
)

// CmdWeb represents the available web sub-command.
Expand Down Expand Up @@ -663,11 +664,11 @@ func runWeb(ctx *cli.Context) error {
var err error
switch setting.Protocol {
case setting.HTTP:
err = runHTTP(listenAddr, m)
err = runHTTP(listenAddr, context2.ClearHandler(m))
case setting.HTTPS:
err = runHTTPS(listenAddr, setting.CertFile, setting.KeyFile, m)
err = runHTTPS(listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
case setting.FCGI:
err = fcgi.Serve(nil, m)
err = fcgi.Serve(nil, context2.ClearHandler(m))
case setting.UnixSocket:
if err := os.Remove(listenAddr); err != nil && !os.IsNotExist(err) {
log.Fatal(4, "Failed to remove unix socket directory %s: %v", listenAddr, err)
Expand All @@ -683,7 +684,7 @@ func runWeb(ctx *cli.Context) error {
if err = os.Chmod(listenAddr, os.FileMode(setting.UnixSocketPermission)); err != nil {
log.Fatal(4, "Failed to set permission of unix socket: %v", err)
}
err = http.Serve(listener, m)
err = http.Serve(listener, context2.ClearHandler(m))
default:
log.Fatal(4, "Invalid protocol: %s", setting.Protocol)
}
Expand Down
4 changes: 3 additions & 1 deletion models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ var migrations = []Migration{
NewMigration("create user column diff view style", createUserColumnDiffViewStyle),
// v15 -> v16
NewMigration("create user column allow create organization", createAllowCreateOrganizationColumn),
// v16
// V16 -> v17
NewMigration("create repo unit table and add units for all repos", addUnitsToTables),
Copy link
Contributor

Choose a reason for hiding this comment

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

This has to go at the end of the list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// v17 -> v18
NewMigration("add external login user", addExternalLoginUser),
}

Expand Down
116 changes: 104 additions & 12 deletions models/migrations/v16.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,117 @@
// Copyright 2016 Gitea. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was the copyright-header removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems to be missing in master (https://github.com/go-gitea/gitea/blob/master/models/migrations/v16.go) and merged removed this, mine is v17.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #992 to fix this missing header in master


import (
"fmt"
"time"

"code.gitea.io/gitea/modules/markdown"

"github.com/go-xorm/xorm"
)

// ExternalLoginUser makes the connecting between some existing user and additional external login sources
type ExternalLoginUser struct {
ExternalID string `xorm:"NOT NULL"`
UserID int64 `xorm:"NOT NULL"`
LoginSourceID int64 `xorm:"NOT NULL"`
// RepoUnit describes all units of a repository
type RepoUnit struct {
ID int64
RepoID int64 `xorm:"INDEX(s)"`
Type int `xorm:"INDEX(s)"`
Index int
Config map[string]string `xorm:"JSON"`
CreatedUnix int64 `xorm:"INDEX CREATED"`
Created time.Time `xorm:"-"`
}

// Enumerate all the unit types
const (
UnitTypeCode = iota + 1 // 1 code
UnitTypeIssues // 2 issues
UnitTypePRs // 3 PRs
UnitTypeCommits // 4 Commits
UnitTypeReleases // 5 Releases
UnitTypeWiki // 6 Wiki
UnitTypeSettings // 7 Settings
UnitTypeExternalWiki // 8 ExternalWiki
UnitTypeExternalTracker // 9 ExternalTracker
)

// Repo describes a repository
type Repo struct {
ID int64
EnableWiki, EnableExternalWiki, EnableIssues, EnableExternalTracker, EnablePulls bool
ExternalWikiURL, ExternalTrackerURL, ExternalTrackerFormat, ExternalTrackerStyle string
}

func addExternalLoginUser(x *xorm.Engine) error {
if err := x.Sync2(new(ExternalLoginUser)); err != nil {
return fmt.Errorf("Sync2: %v", err)
func addUnitsToTables(x *xorm.Engine) error {
var repos []Repo
err := x.Table("repository").Find(&repos)
if err != nil {
return fmt.Errorf("Query repositories: %v", err)
}

sess := x.NewSession()
defer sess.Close()

if err := sess.Begin(); err != nil {
return err
}

var repoUnit RepoUnit
if err := sess.CreateTable(&repoUnit); err != nil {
return fmt.Errorf("CreateTable RepoUnit: %v", err)
}

if err := sess.CreateUniques(&repoUnit); err != nil {
return fmt.Errorf("CreateUniques RepoUnit: %v", err)
}

if err := sess.CreateIndexes(&repoUnit); err != nil {
return fmt.Errorf("CreateIndexes RepoUnit: %v", err)
}

for _, repo := range repos {
for i := 1; i <= 9; i++ {
if (i == UnitTypeWiki || i == UnitTypeExternalWiki) && !repo.EnableWiki {
continue
}
if i == UnitTypeExternalWiki && !repo.EnableExternalWiki {
continue
}
if i == UnitTypePRs && !repo.EnablePulls {
continue
}
if (i == UnitTypeIssues || i == UnitTypeExternalTracker) && !repo.EnableIssues {
continue
}
if i == UnitTypeExternalTracker && !repo.EnableExternalTracker {
continue
}

var config = make(map[string]string)
switch i {
case UnitTypeExternalTracker:
config["ExternalTrackerURL"] = repo.ExternalTrackerURL
config["ExternalTrackerFormat"] = repo.ExternalTrackerFormat
if len(repo.ExternalTrackerStyle) == 0 {
repo.ExternalTrackerStyle = markdown.IssueNameStyleNumeric
}
config["ExternalTrackerStyle"] = repo.ExternalTrackerStyle
case UnitTypeExternalWiki:
config["ExternalWikiURL"] = repo.ExternalWikiURL
}

if _, err = sess.Insert(&RepoUnit{
RepoID: repo.ID,
Type: i,
Index: i,
Config: config,
}); err != nil {
return fmt.Errorf("Insert repo unit: %v", err)
}
}
}

if err := sess.Commit(); err != nil {
return err
}

return nil
}
25 changes: 25 additions & 0 deletions models/migrations/v17.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016 Gitea. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"fmt"

"github.com/go-xorm/xorm"
)

// ExternalLoginUser makes the connecting between some existing user and additional external login sources
type ExternalLoginUser struct {
ExternalID string `xorm:"NOT NULL"`
UserID int64 `xorm:"NOT NULL"`
LoginSourceID int64 `xorm:"NOT NULL"`
}

func addExternalLoginUser(x *xorm.Engine) error {
if err := x.Sync2(new(ExternalLoginUser)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
}
14 changes: 13 additions & 1 deletion routers/user/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ func SignInOAuth(ctx *context.Context) {
return
}

// try to do a direct callback flow, so we don't authenticate the user again but use the valid accesstoken to get the user
user, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
if err == nil && user != nil {
// we got the user without going through the whole OAuth2 authentication flow again
handleOAuth2SignIn(user, gothUser, ctx, err)
return
}

err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp)
if err != nil {
ctx.Handle(500, "SignIn", err)
Expand All @@ -363,6 +371,10 @@ func SignInOAuthCallback(ctx *context.Context) {

u, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)

handleOAuth2SignIn(u, gothUser, ctx, err)
}

func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context, err error) {
if err != nil {
ctx.Handle(500, "UserSignIn", err)
return
Expand Down Expand Up @@ -870,7 +882,7 @@ func ForgotPasswdPost(ctx *context.Context) {
return
}

if !u.IsLocal() {
if !u.IsLocal() && !u.IsOAuth2() {
ctx.Data["Err_Email"] = true
ctx.RenderWithErr(ctx.Tr("auth.non_local_account"), tplForgotPassword, nil)
return
Expand Down
2 changes: 1 addition & 1 deletion templates/user/auth/signup_inner.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{{if not .LinkAccountMode}}
<div class="inline field">
<label></label>
<a href="{{AppSubUrl}}/user/login">{{.i18n.Tr "auth.register_hepler_msg"}}</a>
<a href="{{AppSubUrl}}/user/login">{{.i18n.Tr "auth.register_helper_msg"}}</a>
</div>
{{end}}
{{end}}
Expand Down
23 changes: 23 additions & 0 deletions vendor/github.com/markbates/goth/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading