Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
36eaea6a
Commit
36eaea6a
authored
4 years ago
by
Akshay Bharambe
Browse files
Options
Downloads
Patches
Plain Diff
Refactor: Generate JWT token
parent
adbb3508
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!210
Staging mepdeployment05072020
,
!200
Add: Session control
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
authmdl/jwtmdl/jwtmdl.go
+18
-18
authmdl/jwtmdl/jwtmdl.go
with
18 additions
and
18 deletions
authmdl/jwtmdl/jwtmdl.go
+
18
−
18
View file @
36eaea6a
...
...
@@ -64,24 +64,24 @@ type jwtCustomClaim struct {
// GenerateToken generates JWT token from Login object
func
GenerateToken
(
loginID
string
,
groups
[]
string
,
clientIP
string
,
metadata
gjson
.
Result
,
expirationTime
time
.
Duration
)
(
string
,
error
)
{
claims
:=
jwtCustomClaim
{
UserID
:
loginID
,
Groups
:
groups
,
ClientIP
:
clientIP
,
Metadata
:
metadata
.
String
(),
StandardClaims
:
jwt
.
StandardClaims
{
ExpiresAt
:
time
.
Now
()
.
Add
(
expirationTime
)
.
Unix
(),
},
}
// Create token with claims
token
:=
jwt
.
NewWithClaims
(
jwt
.
SigningMethodHS256
,
claims
)
// Generate encoded token and send it as response.
t
,
err
:=
token
.
SignedString
([]
byte
(
GlobalJWTKey
))
if
errormdl
.
CheckErr
(
err
)
!=
nil
{
loggermdl
.
LogError
(
err
)
return
t
,
errormdl
.
CheckErr
(
err
)
}
return
t
,
nil
//
claims := jwtCustomClaim{
//
UserID: loginID,
//
Groups: groups,
//
ClientIP: clientIP,
//
Metadata: metadata.String(),
//
StandardClaims: jwt.StandardClaims{
//
ExpiresAt: time.Now().Add(expirationTime).Unix(),
//
},
//
}
//
//
Create token with claims
//
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
//
//
Generate encoded token and send it as response.
//
t, err := token.SignedString([]byte(GlobalJWTKey))
//
if errormdl.CheckErr(err) != nil {
//
loggermdl.LogError(err)
//
return t, errormdl.CheckErr(err)
//
}
return
GenerateTokenWithJWTKey
(
loginID
,
groups
,
clientIP
,
metadata
,
expirationTime
,
GlobalJWTKey
)
}
// GenerateTokenWithJWTKey generates JWT token from Login object
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets