aboutsummaryrefslogtreecommitdiff
path: root/server/auth/provider.go
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2017-02-04 23:55:31 +0000
committerNiall Sheridan <nsheridan@gmail.com>2017-02-09 12:49:37 +0000
commit44cb8512c9881687e091cca589a0adcb9f72fa7a (patch)
tree7696577468e3a7aae4f97e129729804817d2ee81 /server/auth/provider.go
parent019891ab8b6709b2e3fb6be83d111fb73ec2bd32 (diff)
Remove the oauth_callback_url config option
Infer the redirect url from the request instead
Diffstat (limited to 'server/auth/provider.go')
-rw-r--r--server/auth/provider.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/server/auth/provider.go b/server/auth/provider.go
index 06dc1c9..d4a8e58 100644
--- a/server/auth/provider.go
+++ b/server/auth/provider.go
@@ -1,11 +1,16 @@
package auth
-import "golang.org/x/oauth2"
+import (
+ "fmt"
+ "net/http"
+
+ "golang.org/x/oauth2"
+)
// Provider is an abstraction of different auth methods.
type Provider interface {
Name() string
- StartSession(string) *Session
+ StartSession(string, *http.Request) *Session
Exchange(string) (*oauth2.Token, error)
Username(*oauth2.Token) string
Valid(*oauth2.Token) bool
@@ -28,3 +33,12 @@ func (s *Session) Authorize(provider Provider, code string) error {
s.Token = t
return nil
}
+
+// Oauth2RedirectURL returns an OAuth redirect_uri for this request.
+func Oauth2RedirectURL(r *http.Request) string {
+ protocol := "http"
+ if r.TLS != nil {
+ protocol = "https"
+ }
+ return fmt.Sprintf("%s://%s/auth/callback", protocol, r.Host)
+}