Browse Source

Fixed goreportcard issues and fixed travis-ci deployment typo

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 8 years ago
parent
commit
39cc78eb06
  1. 2
      .travis.yml
  2. 11
      handlers/auth/auth.go
  3. 1
      handlers/auth/github.go
  4. 3
      handlers/auth/google.go
  5. 2
      util/config.go

2
.travis.yml

@ -12,7 +12,7 @@ script:
deploy: deploy:
provider: bintray provider: bintray
user: maxibanki user: maxibanki
file: "build/descriptor.json" file: "build/bintray.json"
key: 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= 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: notifications:

11
handlers/auth/auth.go

@ -16,7 +16,7 @@ import (
// Adapter will be implemented by each oAuth provider // Adapter will be implemented by each oAuth provider
type Adapter interface { type Adapter interface {
GetRedirectURl(state string) string GetRedirectURL(state string) string
GetUserData(state, code string) (*user, error) GetUserData(state, code string) (*user, error)
GetOAuthProviderName() string GetOAuthProviderName() string
} }
@ -25,6 +25,7 @@ type user struct {
ID, Name, Picture string ID, Name, Picture string
} }
// JWTClaims are the data and general information which is stored in the JWT
type JWTClaims struct { type JWTClaims struct {
jwt.StandardClaims jwt.StandardClaims
OAuthProvider string OAuthProvider string
@ -33,8 +34,11 @@ type JWTClaims struct {
OAuthPicture string OAuthPicture string
} }
// AdapterWrapper wraps an normal oAuth Adapter with some generic functions
// to be implemented directly by the gin router
type AdapterWrapper struct{ Adapter } 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 { func WithAdapterWrapper(a Adapter, h *gin.RouterGroup) *AdapterWrapper {
aw := &AdapterWrapper{a} aw := &AdapterWrapper{a}
h.GET("/login", aw.HandleLogin) h.GET("/login", aw.HandleLogin)
@ -42,14 +46,17 @@ func WithAdapterWrapper(a Adapter, h *gin.RouterGroup) *AdapterWrapper {
return aw 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) { func (a *AdapterWrapper) HandleLogin(c *gin.Context) {
state := a.randToken() state := a.randToken()
session := sessions.Default(c) session := sessions.Default(c)
session.Set("state", state) session.Set("state", state)
session.Save() 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) { func (a *AdapterWrapper) HandleCallback(c *gin.Context) {
session := sessions.Default(c) session := sessions.Default(c)
sessionState := session.Get("state") sessionState := session.Get("state")

1
handlers/auth/github.go

@ -1,2 +1 @@
package auth package auth

3
handlers/auth/google.go

@ -14,6 +14,7 @@ type googleAdapter struct {
config *oauth2.Config config *oauth2.Config
} }
// NewGoogleAdapter creates an oAuth adapter out of the credentials and the baseURL
func NewGoogleAdapter(clientID, clientSecret, baseURL string) Adapter { func NewGoogleAdapter(clientID, clientSecret, baseURL string) Adapter {
return &googleAdapter{&oauth2.Config{ return &googleAdapter{&oauth2.Config{
ClientID: clientID, 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) return a.config.AuthCodeURL(state)
} }

2
util/config.go

@ -11,6 +11,8 @@ import (
var ( var (
dataDirPath string dataDirPath string
// DoNotSetConfigName is used to predefine if the ConfigName should be set.
// used for the unit testing reason
DoNotSetConfigName = false DoNotSetConfigName = false
) )

Loading…
Cancel
Save