Skip to content

Commit ab30ffb

Browse files
committed
gasper changes for gctltoken generation
1 parent 8dc02a0 commit ab30ffb

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/master/middlewares/jwt.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ func authenticator(c *gin.Context) (interface{}, error) {
3434
return user, nil
3535
}
3636

37+
func authenticatorForGctl(c *gin.Context) (interface{}, error) {
38+
auth := &types.Login{}
39+
if err := c.ShouldBind(auth); err != nil {
40+
return nil, errMissingCredentials
41+
}
42+
user, err := mongo.FetchSingleUser(auth.GetEmail())
43+
if err != nil || user == nil {
44+
return nil, errFailedAuthentication
45+
}
46+
47+
return user, nil
48+
}
49+
3750
func payloadFunc(data interface{}) jwt.MapClaims {
3851
if user, ok := data.(*types.User); ok {
3952
return jwt.MapClaims{
@@ -157,7 +170,7 @@ var JWTGctl = &jwt.GinJWTMiddleware{
157170
TokenLookup: "header: Authorization",
158171
TokenHeadName: "gctlToken",
159172
TimeFunc: time.Now,
160-
Authenticator: authenticator,
173+
Authenticator: authenticatorForGctl,
161174
PayloadFunc: payloadFuncForGctl,
162175
IdentityHandler: identityHandlerForGctl,
163176
Authorizator: authorizatorForGctl,

services/master/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func NewService() http.Handler {
5555
auth.PUT("/revoke", c.RevokeToken)
5656
}
5757

58+
auth.POST("/gctltoken", m.AuthRequired(), m.LoginHandler)
5859
router.GET("/instances", m.AuthRequired(), c.FetchAllInstancesByUser)
5960
router.POST("/gctllogin", m.JWTGctl.MiddlewareFunc(), c.GctlLogin)
6061

0 commit comments

Comments
 (0)