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
8294bb94
Commit
8294bb94
authored
5 months ago
by
Prajwal Patil
Browse files
Options
Downloads
Patches
Plain Diff
Implemented JWT KID
parent
0f15c531
Branches
jwtkidfeature
Branches containing commit
Tags
Tags containing commit
4 merge requests
!302
merge devbranch into staging
,
!299
Devbranch
,
!296
merge devbranch to staging.
,
!294
#30 Implemented JWT KID
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
authmdl/jwtmdl/jwtmdl.go
+40
-3
authmdl/jwtmdl/jwtmdl.go
with
40 additions
and
3 deletions
authmdl/jwtmdl/jwtmdl.go
+
40
−
3
View file @
8294bb94
...
...
@@ -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
)
...
...
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