-
Notifications
You must be signed in to change notification settings - Fork 0
/
jwt.go
32 lines (24 loc) · 945 Bytes
/
jwt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package auth
import (
ginjwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"github.com/bolo-tourism/go/bolo/pkg/middleware"
)
// AuthzAudience defines the value of jwt audience field.
const AuthzAudience = "iam.authz.marmotedu.com"
// JWTStrategy defines jwt bearer authentication strategy.
type JWTStrategy struct {
ginjwt.GinJWTMiddleware
}
var _ middleware.AuthStrategy = &JWTStrategy{}
// NewJWTStrategy create jwt bearer strategy with GinJWTMiddleware.
func NewJWTStrategy(gjwt ginjwt.GinJWTMiddleware) JWTStrategy {
return JWTStrategy{gjwt}
}
// AuthFunc defines jwt bearer strategy as the gin authentication middleware.
func (j JWTStrategy) AuthFunc() gin.HandlerFunc {
return j.MiddlewareFunc()
}