diff --git a/examples/aisle/x_test.db b/examples/aisle/x_test.db index 4dc92452..a7eed689 100644 Binary files a/examples/aisle/x_test.db and b/examples/aisle/x_test.db differ diff --git a/examples/aisle/x_test_localhost.db b/examples/aisle/x_test_localhost.db index 09f2340f..9b994d1a 100644 Binary files a/examples/aisle/x_test_localhost.db and b/examples/aisle/x_test_localhost.db differ diff --git a/examples/scene/x_test.db b/examples/scene/x_test.db index 20d86127..112ea4d7 100644 Binary files a/examples/scene/x_test.db and b/examples/scene/x_test.db differ diff --git a/platform/api/app.auth.go b/platform/api/app.auth.go index 65908f3a..11629486 100644 --- a/platform/api/app.auth.go +++ b/platform/api/app.auth.go @@ -10,19 +10,19 @@ import ( ) // Provider deifned TODO -type Provider interface { - GetName() string - Config(*Identity) - Verify(*Context) (TokenInfo, bool) - Ticket(userId, extra string, ctx *Context) (TokenInfo, error) -} - -// Identity deifned TODO -type Identity struct { - jwt *JWT - OAuth2 *server.Server - providers []Provider -} +type ( + Provider interface { + GetName() string + Config(*Identity) + Verify(*Context) (TokenInfo, bool) + Ticket(userId, extra string, ctx *Context) (TokenInfo, error) + } + Identity struct { + JWT *JWT + OAuth2 *server.Server + providers []Provider + } +) // RegisterProvider register auth provider func (i *Identity) RegisterProvider(provider Provider) { diff --git a/platform/api/app.auth.jwt.go b/platform/api/app.auth.jwt.go index ddefd42e..b665ca39 100644 --- a/platform/api/app.auth.jwt.go +++ b/platform/api/app.auth.jwt.go @@ -27,8 +27,8 @@ func NewJWT(secret string, expire int64) *JWT { } } -// BearerAuth defined TODO -func (j *JWT) BearerAuth(req *http.Request) (string, bool) { +// Bearer defined TODO +func (j *JWT) Bearer(req *http.Request) (string, bool) { prefix, auth := "Bearer ", req.Header.Get("Authorization") if strings.HasPrefix(auth, prefix) { return auth[len(prefix):], true @@ -77,7 +77,7 @@ func (p *JWTProvider) GetName() string { // Config defined TODO func (p *JWTProvider) Config(i *Identity) { - p.jwt = i.jwt + p.jwt = i.JWT } // parseToken defined TODO @@ -90,7 +90,7 @@ func (p *JWTProvider) parseJWTToken(t *jwt.MapClaims) TokenInfo { // Verify defined TODO func (p *JWTProvider) Verify(ctx *Context) (TokenInfo, bool) { - if bearer, ok := p.jwt.BearerAuth(ctx.Request()); ok { + if bearer, ok := p.jwt.Bearer(ctx.Request()); ok { tk, err := p.jwt.LoadAccessToken(bearer) if err != nil { logrus.Error(err) diff --git a/platform/api/app.go b/platform/api/app.go index dc764302..7cf31d16 100755 --- a/platform/api/app.go +++ b/platform/api/app.go @@ -82,7 +82,7 @@ func WithIdentity() Option { manager.SetValidateURIHandler(ValidateURIHandler) dol.Identity = &Identity{} - dol.Identity.jwt = NewJWT(viper.GetString("jwt.secret"), viper.GetInt64("jwt.expire")) + dol.Identity.JWT = NewJWT(viper.GetString("jwt.secret"), viper.GetInt64("jwt.expire")) dol.Identity.OAuth2 = server.NewServer(server.NewConfig(), manager) dol.Identity.OAuth2.SetUserAuthorizationHandler(UserAuthorizationHandler) dol.Identity.OAuth2.SetInternalErrorHandler(func(err error) (re *errors.Response) { logrus.Error(err); return }) diff --git a/platform/x_test.db b/platform/x_test.db index 3f948710..8ca8b987 100644 Binary files a/platform/x_test.db and b/platform/x_test.db differ