Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from gogf/qiangg_jwt
Browse files Browse the repository at this point in the history
update some details
zhaopengme authored Mar 26, 2019

Verified

This commit was signed with the committer’s verified signature.
ctavan Christoph Tavan
2 parents a40ac14 + 0d56941 commit 9d42a0f
Showing 7 changed files with 27 additions and 38 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# gf-jwt
Gf jwt plugin
GF jwt plugin

This plugin is forked [https://github.com/appleboy/gin-jwt](https://github.com/appleboy/gin-jwt) plugin, modified to [https://github.com/gogf/ Gf](https://github.com/gogf/gf) plugin.
This plugin is forked [https://github.com/appleboy/gin-jwt](https://github.com/appleboy/gin-jwt) plugin, modified to [https://github.com/gogf/gf](https://github.com/gogf/gf) plugin.


[英文](README.md) [中文](README_zh.md)
@@ -12,13 +12,13 @@ This plugin is forked [https://github.com/appleboy/gin-jwt](https://github.com/a
Download and install

```sh
$ go get github.com/zhaopengme/gf-jwt
$ go get github.com/gogf/gf-jwt
```

Import

```go
Import "github.com/zhaopengme/gf-jwt"
import "github.com/gogf/gf-jwt"
```

## example
@@ -34,7 +34,7 @@ import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
"github.com/gogf/gf/g/util/gvalid"
"github.com/zhaopengme/gf-jwt"
"github.com/gogf/gf-jwt"
"log"
"net/http"
"time"
10 changes: 5 additions & 5 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# gf-jwt
gf 的 jwt 插件
gf 的 jwt 插件

这个插件是 fork 了 [https://github.com/appleboy/gin-jwt](https://github.com/appleboy/gin-jwt) 插件,修改为 [https://github.com/gogf/gf](https://github.com/gogf/gf) 插件.

@@ -12,13 +12,13 @@ gf 的 jwt 插件
下载安装

```sh
$ go get github.com/zhaopengme/gf-jwt
$ go get github.com/gogf/gf-jwt
```

导入

```go
import "github.com/zhaopengme/gf-jwt"
import "github.com/gogf/gf-jwt"
```

## 例子
@@ -34,7 +34,7 @@ import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
"github.com/gogf/gf/g/util/gvalid"
"github.com/zhaopengme/gf-jwt"
"github.com/gogf/gf-jwt"
"log"
"net/http"
"time"
@@ -187,4 +187,4 @@ $ http -f GET localhost:8000/user/hello "Authorization:Bearer xxxxxxxxx" "Conte
![api screenshot](screenshot/401.png)


再次感谢[https://github.com/appleboy/gin-jwt](https://github.com/appleboy/gin-jwt)
再次感谢[https://github.com/appleboy/gin-jwt](https://github.com/appleboy/gin-jwt)
20 changes: 9 additions & 11 deletions auth_jwt.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package jwt

import (
"crypto/rsa"
"errors"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
"io/ioutil"
"net/http"
"strings"
"time"

"github.com/dgrijalva/jwt-go"
"crypto/rsa"
"errors"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
"io/ioutil"
"net/http"
"strings"
"time"
)

// MapClaims type that uses the map[string]interface{} for JSON decoding
@@ -322,7 +320,7 @@ func (mw *GfJWTMiddleware) MiddlewareInit() error {
}

if mw.Realm == "" {
mw.Realm = "gin jwt"
mw.Realm = "gf jwt"
}

if mw.CookieName == "" {
6 changes: 3 additions & 3 deletions example/auth/index.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package auth

import (
"github.com/gogf/gf-jwt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
"github.com/gogf/gf/g/util/gvalid"
"github.com/zhaopengme/gf-jwt"
"log"
"net/http"
"time"
@@ -89,8 +89,8 @@ func (d *Default) Authenticator(r *ghttp.Request) (interface{}, error) {
if e := gvalid.CheckMap(data, d.Rules); e != nil {
return "", jwt.ErrFailedAuthentication
}
if (data["username"] == "admin" && data["password"] == "admin") {
return g.Map{
if data["username"] == "admin" && data["password"] == "admin" {
return g.Map {
"username": data["username"],
"id": data["username"],
}, nil
6 changes: 3 additions & 3 deletions example/server/index.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package main

import (
"github.com/gogf/gf-jwt/example/auth"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
"github.com/zhaopengme/gf-jwt/example/auth"
)

func hello(r *ghttp.Request) {
r.Response.Write("哈喽世界!")
r.Response.Write("Hello World!")
}

func main() {
@@ -27,7 +27,7 @@ func main() {
})

s.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("it's work!")
r.Response.Write("It works!")
})
s.SetPort(8000)
s.Run()
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/zhaopengme/gf-jwt
module github.com/gogf/gf-jwt

require (
github.com/gogf/gf v1.5.16
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gogf/gf v1.5.15
google.golang.org/appengine v1.4.0 // indirect
)
9 changes: 0 additions & 9 deletions go.sum

This file was deleted.

0 comments on commit 9d42a0f

Please sign in to comment.