Skip to content
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

Add authenticated user info to HTTP header #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (a *GoogleAuth) Authenticate(domain []string, c martini.Context, tokens oau
if user != nil {
log.Printf("user %s logged in", email)
c.Map(user)
if userKey := a.conf.Auth.Header.UserKey; userKey != "" {
r.Header.Set(userKey, email)
}
} else {
log.Printf("email doesn't allow: %s", email)
forbidden(w)
Expand Down
5 changes: 5 additions & 0 deletions conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type SSLConf struct {
type AuthConf struct {
Session AuthSessionConf `yaml:"session"`
Info AuthInfoConf `yaml:"info"`
Header AuthHeaderConf `yaml:"header"`
}

type AuthSessionConf struct {
Expand All @@ -38,6 +39,10 @@ type AuthInfoConf struct {
ApiEndpoint string `yaml:"api_endpoint"`
}

type AuthHeaderConf struct {
UserKey string `yaml:"user_key"`
}

type ProxyConf struct {
Path string `yaml:"path"`
Dest string `yaml:"dest"`
Expand Down
4 changes: 4 additions & 0 deletions config_sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ auth:
# your app redirect_url for the service: if the service is Google, path is always "/oauth2callback"
redirect_url: https://yourapp.example.com/oauth2callback

# # HTTP request header definitions (optional)
# header:
# user_key: your key # field name for authenticated user info (ex. x-gate-user)

# # restrict user request. (optional)
# restrictions:
# - yourdomain.com # domain of your Google App (Google)
Expand Down
7 changes: 7 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ auth:
client_secret: 'secret client secret'
redirect_url: 'http://example.com/oauth2callback'

header:
user_key: 'x-gate-user'

htdocs: ./

proxy:
Expand All @@ -48,6 +51,10 @@ proxy:
if conf.Addr != ":9999" {
t.Errorf("unexpected address: %s", conf.Addr)
}

if conf.Auth.Header.UserKey != "x-gate-user" {
t.Errorf("unexpected auth header user key: %s", conf.Auth.Header.UserKey)
}
}

func TestParseMultiRestrictions(t *testing.T) {
Expand Down