diff --git a/.travis.yml b/.travis.yml index b1758b4..7ee1b75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ script: deploy: provider: bintray user: maxibanki - file: "build/descriptor.json" + file: "build/bintray.json" key: secure: ErqvSFIlL3d9XuMj+T+hO6xZqll8Ubx0DEdHD6NJKi7sH7Be3b3/vUoPdAjdFOP70DhaccbncGCTPZ9hsNKdqYxZmuKx3WWwH4H4U5YdDIViXtH6+B5KdAmvdZIynaj+THQAbVAhr+QyvcqotNySPd3Ac1HCg2YAcUHme6y3FsiRJ79To80JWxTSR1G/oObmeoDn8R18wmH1gHl8KQ7ltC537Osb/H34bJ/hY94hRe8IEmoQE4yz/EP44kGXRb/F87i92y1mO081ZS1I1hs5Kbom43YoItqSVbJP/abPMyCsGDv2FGXaGqk5IVC1k+01pcAjqxCzMvXC272itc0E8OEWqE4qONN+m2S9tyALyOaUZ7j5meWLHQj49Rzo7XIWh1PvvEMovdl/wk/Oc9f0ZywPuvoRht5ZebgXbPWAMMNywwy0GKM4nU0DCyFm23mlzPh4iklo12gEUzq3YLc18RhAZuy4timeevrDCuJMQeQ3sqcQBKCQ+rdOxzVCKKl2sGpNaTJEYaHGT9KLCEGBLmvaB58RKgmGN6IIEwpxSm2SGoirfnQsr+DP+kaSvWPr6R/pZAhO1JzO+azaXvfr+hL2SMX6U7j5+SDmFGIFDwxok7ny1QUTQXKlNzA/ks9/vufe30hrTkph/MfEvM5mYVbfgAn5zZ0v+dJ2wCoe1go= notifications: diff --git a/handlers/auth/auth.go b/handlers/auth/auth.go index 64d9a62..916d8e0 100644 --- a/handlers/auth/auth.go +++ b/handlers/auth/auth.go @@ -16,7 +16,7 @@ import ( // Adapter will be implemented by each oAuth provider type Adapter interface { - GetRedirectURl(state string) string + GetRedirectURL(state string) string GetUserData(state, code string) (*user, error) GetOAuthProviderName() string } @@ -25,6 +25,7 @@ type user struct { ID, Name, Picture string } +// JWTClaims are the data and general information which is stored in the JWT type JWTClaims struct { jwt.StandardClaims OAuthProvider string @@ -33,8 +34,11 @@ type JWTClaims struct { OAuthPicture string } +// AdapterWrapper wraps an normal oAuth Adapter with some generic functions +// to be implemented directly by the gin router type AdapterWrapper struct{ Adapter } +// WithAdapterWrapper creates an adapterWrapper out of the oAuth Adapter and an gin.RouterGroup func WithAdapterWrapper(a Adapter, h *gin.RouterGroup) *AdapterWrapper { aw := &AdapterWrapper{a} h.GET("/login", aw.HandleLogin) @@ -42,14 +46,17 @@ func WithAdapterWrapper(a Adapter, h *gin.RouterGroup) *AdapterWrapper { return aw } +// HandleLogin handles the incoming http request for the oAuth process +// and redirects to the generated URL of the provider func (a *AdapterWrapper) HandleLogin(c *gin.Context) { state := a.randToken() session := sessions.Default(c) session.Set("state", state) session.Save() - c.Redirect(http.StatusTemporaryRedirect, a.GetRedirectURl(state)) + c.Redirect(http.StatusTemporaryRedirect, a.GetRedirectURL(state)) } +// HandleCallback handles and validates the callback which is coming back from the oAuth request func (a *AdapterWrapper) HandleCallback(c *gin.Context) { session := sessions.Default(c) sessionState := session.Get("state") diff --git a/handlers/auth/github.go b/handlers/auth/github.go index 9a72978..8832b06 100644 --- a/handlers/auth/github.go +++ b/handlers/auth/github.go @@ -1,2 +1 @@ package auth - diff --git a/handlers/auth/google.go b/handlers/auth/google.go index 90faeec..828d4a2 100644 --- a/handlers/auth/google.go +++ b/handlers/auth/google.go @@ -14,6 +14,7 @@ type googleAdapter struct { config *oauth2.Config } +// NewGoogleAdapter creates an oAuth adapter out of the credentials and the baseURL func NewGoogleAdapter(clientID, clientSecret, baseURL string) Adapter { return &googleAdapter{&oauth2.Config{ ClientID: clientID, @@ -26,7 +27,7 @@ func NewGoogleAdapter(clientID, clientSecret, baseURL string) Adapter { }} } -func (a *googleAdapter) GetRedirectURl(state string) string { +func (a *googleAdapter) GetRedirectURL(state string) string { return a.config.AuthCodeURL(state) } diff --git a/util/config.go b/util/config.go index 7998819..3a982ee 100644 --- a/util/config.go +++ b/util/config.go @@ -10,7 +10,9 @@ import ( ) var ( - dataDirPath string + dataDirPath string + // DoNotSetConfigName is used to predefine if the ConfigName should be set. + // used for the unit testing reason DoNotSetConfigName = false )