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
Merge requests
!294
An error occurred while fetching the assigned milestone of the selected merge_request.
#30
Implemented JWT KID
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
#30
Implemented JWT KID
jwtkidfeature
into
devbranch
Overview
1
Commits
1
Pipelines
0
Changes
1
Merged
Prajwal Patil
requested to merge
jwtkidfeature
into
devbranch
5 months ago
Overview
1
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
devbranch
devbranch (base)
and
latest version
latest version
8294bb94
1 commit,
5 months ago
1 file
+
40
−
3
Expand all files
Preferences
File browser
List view
Tree view
Compare changes
Inline
Side-by-side
Show whitespace changes
Show one file at a time
authmdl/jwtmdl/jwtmdl.go
+
40
−
3
Options
@@ -2,6 +2,7 @@ package jwtmdl
import
(
"strings"
"sync"
"time"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/authmdl/sessionmdl"
@@ -10,12 +11,48 @@ import (
"github.com/tidwall/gjson"
)
// map to store kid
type
Jwtkid
struct
{
jwtKidMap
map
[
string
]
string
mu
sync
.
Mutex
}
func
(
j
*
Jwtkid
)
Get
(
kid
string
)
(
string
,
bool
)
{
j
.
mu
.
Lock
()
defer
j
.
mu
.
Unlock
()
key
,
ok
:=
j
.
jwtKidMap
[
kid
]
return
key
,
ok
}
func
(
j
*
Jwtkid
)
Set
(
kid
,
key
string
)
{
j
.
mu
.
Lock
()
defer
j
.
mu
.
Unlock
()
j
.
jwtKidMap
[
kid
]
=
key
}
// jwtKidStore - store to keep kid and jwtKey
var
jwtKidStore
=
Jwtkid
{
jwtKidMap
:
make
(
map
[
string
]
string
)}
// GlobalJWTKey - key to decode and encode token
var
GlobalJWTKey
string
var
keyFunc
=
func
(
key
string
)
jwt
.
Keyfunc
{
return
func
(
*
jwt
.
Token
)
(
interface
{},
error
)
{
return
[]
byte
(
key
),
nil
return
func
(
token
*
jwt
.
Token
)
(
interface
{},
error
)
{
if
kid
,
ok
:=
token
.
Header
[
"kid"
]
.
(
string
);
ok
{
if
jwtKey
,
ok
:=
jwtKidStore
.
Get
(
kid
);
ok
&&
jwtKey
==
"DEFAULTKEY"
{
return
([]
byte
(
key
)),
nil
}
if
jwtKey
,
exists
:=
jwtKidStore
.
Get
(
kid
);
exists
{
return
([]
byte
(
jwtKey
)),
nil
}
}
b
:=
([]
byte
(
key
))
return
b
,
nil
}
}
func
InitJwtKidStore
(
kidConfig
gjson
.
Result
)
{
for
_
,
kid
:=
range
kidConfig
.
Array
()
{
jwtKidStore
.
Set
(
kid
.
Get
(
"kid"
)
.
String
(),
kid
.
Get
(
"jwtKey"
)
.
String
())
}
}
@@ -118,7 +155,7 @@ func GenerateTokenWithJWTKey(loginID string, groups []string, clientIP string, m
return
generate
(
claims
,
JWTKey
)
}
//GeneratePricipleObjUsingToken GeneratePricipleObjUsingToken
//
GeneratePricipleObjUsingToken GeneratePricipleObjUsingToken
func
GeneratePricipleObjUsingToken
(
tokenReq
string
,
jwtKey
string
)
(
jwt
.
MapClaims
,
error
)
{
token
,
err
:=
extract
(
tokenReq
)
Menu
Explore
Projects
Groups
Topics
Snippets