Skip to content

Commit fd1a268

Browse files
committed
feat: GCTL Token generation through SWS
1 parent 8dc02a0 commit fd1a268

File tree

582 files changed

+749
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

582 files changed

+749
-191
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/genssh/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package genssh

services/master/controllers/term.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package controllers

services/master/middlewares/jwt.go

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

37+
// AuthenticatorForGctl doesn't authenticate. Authentication to be done in middleware before invoking this function.
38+
// This function only gets the user details.
39+
func authenticatorForGctl(c *gin.Context) (interface{}, error) {
40+
auth := &types.GCTLToken{}
41+
if err := c.ShouldBind(auth); err != nil {
42+
return nil, errMissingCredentials
43+
}
44+
user, err := mongo.FetchSingleUser(auth.GetEmail())
45+
if err != nil || user == nil {
46+
return nil, errFailedAuthentication
47+
}
48+
49+
return user, nil
50+
}
51+
3752
func payloadFunc(data interface{}) jwt.MapClaims {
3853
if user, ok := data.(*types.User); ok {
3954
return jwt.MapClaims{
@@ -157,7 +172,7 @@ var JWTGctl = &jwt.GinJWTMiddleware{
157172
TokenLookup: "header: Authorization",
158173
TokenHeadName: "gctlToken",
159174
TimeFunc: time.Now,
160-
Authenticator: authenticator,
175+
Authenticator: authenticatorForGctl,
161176
PayloadFunc: payloadFuncForGctl,
162177
IdentityHandler: identityHandlerForGctl,
163178
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("/pat", m.AuthRequired(), m.LoginHandler)
5859
router.GET("/instances", m.AuthRequired(), c.FetchAllInstancesByUser)
5960
router.POST("/gctllogin", m.JWTGctl.MiddlewareFunc(), c.GctlLogin)
6061

types/user.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,14 @@ func (pw *PasswordUpdate) GetOldPassword() string {
9999
func (pw *PasswordUpdate) GetNewPassword() string {
100100
return pw.NewPassword
101101
}
102+
103+
// GCTLToken is the request body for generating GCTLToken
104+
type GCTLToken struct {
105+
Email string `form:"email" json:"email" bson:"email" binding:"required"`
106+
Token string `form:"token" json:"token" bson:"token" binding:"required"`
107+
}
108+
109+
// GetEmail returns the email of the user
110+
func (auth *GCTLToken) GetEmail() string {
111+
return auth.Email
112+
}

vendor/github.com/BurntSushi/toml/encoding_types.go

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

vendor/github.com/BurntSushi/toml/encoding_types_1.1.go

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

vendor/github.com/Microsoft/go-winio/backup.go

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

vendor/github.com/Microsoft/go-winio/file.go

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

0 commit comments

Comments
 (0)