Skip to content

Commit

Permalink
refactor: [cache skip] update import path (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy authored Jan 25, 2017
1 parent 6d2e9e1 commit 25c1ff7
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 117 deletions.
7 changes: 0 additions & 7 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ pipeline:
- coverage all
- make coverage

line:
image: appleboy/drone-line
pull: true
to: u359650f919427b5229330c7205c47ee4
when:
status: [ success, failure ]

facebook:
image: appleboy/drone-facebook
pull: true
Expand Down
2 changes: 1 addition & 1 deletion .drone.yml.sig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eyJhbGciOiJIUzI1NiJ9.cGlwZWxpbmU6CiAgcmVzdG9yZV9jYWNoZToKICAgIGltYWdlOiBhcHBsZWJveS9kcm9uZS1zZnRwLWNhY2hlCiAgICBwdWxsOiB0cnVlCiAgICByZXN0b3JlOiB0cnVlCiAgICBtb3VudDogWyAuZ2xpZGUsIHZlbmRvciBdCiAgICBpZ25vcmVfYnJhbmNoOiB0cnVlCgogIGJ1aWxkOgogICAgaW1hZ2U6IGFwcGxlYm95L2dvbGFuZy10ZXN0aW5nOiR7R09fVkVSU0lPTn0KICAgIGVudmlyb25tZW50OgogICAgICAtIEdPUEFUSD0vZ28KICAgIGNvbW1hbmRzOgogICAgICAtIG1ha2UgaW5zdGFsbAogICAgICAtIG1ha2UgdmV0CiAgICAgIC0gbWFrZSBsaW50CiAgICAgIC0gY292ZXJhZ2UgYWxsCiAgICAgIC0gbWFrZSBjb3ZlcmFnZQoKICBsaW5lOgogICAgaW1hZ2U6IGFwcGxlYm95L2Ryb25lLWxpbmUKICAgIHB1bGw6IHRydWUKICAgIHRvOiB1MzU5NjUwZjkxOTQyN2I1MjI5MzMwYzcyMDVjNDdlZTQKICAgIHdoZW46CiAgICAgIHN0YXR1czogWyBzdWNjZXNzLCBmYWlsdXJlIF0KCiAgZmFjZWJvb2s6CiAgICBp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WdlOiBhcHBsZWJveS9kcm9uZS1mYWNlYm9vawogICAgcHVsbDogdHJ1ZQogICAgdG86IDEyMzQ5NzMzODY1MjQ2MTAKICAgIHdoZW46CiAgICAgIHN0YXR1czogWyBzdWNjZXNzLCBmYWlsdXJlIF0KCiAgcmVidWlsZF9jYWNoZToKICAgIGltYWdlOiBhcHBsZWJveS9kcm9uZS1zZnRwLWNhY2hlCiAgICBwdWxsOiB0cnVlCiAgICByZWJ1aWxkOiB0cnVlCiAgICBtb3VudDogWyAuZ2xpZGUsIHZlbmRvciBdCiAgICBpZ25vcmVfYnJhbmNoOiB0cnVlCiAgICB3aGVuOgogICAgICBicmFuY2g6IG1hc3RlcgoKd29ya3NwYWNlOgogIHBhdGg6IC9nby9zcmMvZ2l0aHViLmNvbS9hcHBsZWJveS9naW4tand0CgptYXRyaXg6CiAgR09fVkVSU0lPTjoKICAgIC0gMS42LjQKICAgIC0gMS43LjQK.bTzZ2unl2LhX23wI32w1d6_o4CxDZVdpmC-kLoX8bW0
133 changes: 67 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,77 +44,78 @@ Please see [server example file](example/server.go).
package main

import (
"gopkg.in/appleboy/gin-jwt.v2"
"github.com/fvbock/endless"
"github.com/gin-gonic/gin"
"os"
"time"
"net/http"
"os"
"time"

"gopkg.in/appleboy/gin-jwt.v2"
"gopkg.in/gin-gonic/gin.v1"
)

func HelloHandler(c *gin.Context) {
c.JSON(200, gin.H{
"text": "Hello World.",
})
func helloHandler(c *gin.Context) {
c.JSON(200, gin.H{
"text": "Hello World.",
})
}

func main() {
port := os.Getenv("PORT")
r := gin.New()
r.Use(gin.Logger())
r.Use(gin.Recovery())

if port == "" {
port = "8000"
}

// the jwt middleware
authMiddleware := &jwt.GinJWTMiddleware{
Realm: "test zone",
Key: []byte("secret key"),
Timeout: time.Hour,
MaxRefresh: time.Hour * 24,
Authenticator: func(userId string, password string, c *gin.Context) (string, bool) {
if (userId == "admin" && password == "admin") || (userId == "test" && password == "test") {
return userId, true
}

return userId, false
},
Authorizator: func(userId string, c *gin.Context) bool {
if userId == "admin" {
return true
}

return false
},
Unauthorized: func(c *gin.Context, code int, message string) {
c.JSON(code, gin.H{
"code": code,
"message": message,
})
},
// TokenLookup is a string in the form of "<source>:<name>" that is used
// to extract token from the request.
// Optional. Default value "header:Authorization".
// Possible values:
// - "header:<name>"
// - "query:<name>"
// - "cookie:<name>"
TokenLookup: "header:Authorization",
// TokenLookup: "query:token",
// TokenLookup: "cookie:token",
}

r.POST("/login", authMiddleware.LoginHandler)

auth := r.Group("/auth")
auth.Use(authMiddleware.MiddlewareFunc())
{
auth.GET("/hello", HelloHandler)
auth.GET("/refresh_token", authMiddleware.RefreshHandler)
}

endless.ListenAndServe(":"+port, r)
port := os.Getenv("PORT")
r := gin.New()
r.Use(gin.Logger())
r.Use(gin.Recovery())

if port == "" {
port = "8000"
}

// the jwt middleware
authMiddleware := &jwt.GinJWTMiddleware{
Realm: "test zone",
Key: []byte("secret key"),
Timeout: time.Hour,
MaxRefresh: time.Hour,
Authenticator: func(userId string, password string, c *gin.Context) (string, bool) {
if (userId == "admin" && password == "admin") || (userId == "test" && password == "test") {
return userId, true
}

return userId, false
},
Authorizator: func(userId string, c *gin.Context) bool {
if userId == "admin" {
return true
}

return false
},
Unauthorized: func(c *gin.Context, code int, message string) {
c.JSON(code, gin.H{
"code": code,
"message": message,
})
},
// TokenLookup is a string in the form of "<source>:<name>" that is used
// to extract token from the request.
// Optional. Default value "header:Authorization".
// Possible values:
// - "header:<name>"
// - "query:<name>"
// - "cookie:<name>"
TokenLookup: "header:Authorization",
// TokenLookup: "query:token",
// TokenLookup: "cookie:token",
}

r.POST("/login", authMiddleware.LoginHandler)

auth := r.Group("/auth")
auth.Use(authMiddleware.MiddlewareFunc())
{
auth.GET("/hello", helloHandler)
auth.GET("/refresh_token", authMiddleware.RefreshHandler)
}

http.ListenAndServe(":"+port, r)
}
```

Expand Down
5 changes: 3 additions & 2 deletions auth_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package jwt

import (
"errors"
"github.com/gin-gonic/gin"
"gopkg.in/dgrijalva/jwt-go.v3"
"net/http"
"strings"
"time"

"gopkg.in/dgrijalva/jwt-go.v3"
"gopkg.in/gin-gonic/gin.v1"
)

// GinJWTMiddleware provides a Json-Web-Token authentication implementation. On failure, a 401 HTTP response
Expand Down
11 changes: 6 additions & 5 deletions auth_jwt_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package jwt

import (
"github.com/buger/jsonparser"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"gopkg.in/appleboy/gofight.v1"
"gopkg.in/dgrijalva/jwt-go.v3"
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/buger/jsonparser"
"github.com/stretchr/testify/assert"
"gopkg.in/appleboy/gofight.v1"
"gopkg.in/dgrijalva/jwt-go.v3"
"gopkg.in/gin-gonic/gin.v1"
)

var (
Expand Down
9 changes: 5 additions & 4 deletions example/server.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"github.com/fvbock/endless"
"github.com/gin-gonic/gin"
"gopkg.in/appleboy/gin-jwt.v2"
"net/http"
"os"
"time"

"github.com/appleboy/gin-jwt"
"gopkg.in/gin-gonic/gin.v1"
)

func helloHandler(c *gin.Context) {
Expand Down Expand Up @@ -71,5 +72,5 @@ func main() {
auth.GET("/refresh_token", authMiddleware.RefreshHandler)
}

endless.ListenAndServe(":"+port, r)
http.ListenAndServe(":"+port, r)
}
42 changes: 13 additions & 29 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package: github.com/appleboy/gin-jwt
import:
- package: github.com/fvbock/endless
- package: github.com/gin-gonic/gin
- package: gopkg.in/dgrijalva/jwt-go.v3
- package: gopkg.in/appleboy/gin-jwt.v2
version: ^3.0.0
- package: gopkg.in/gin-gonic/gin.v1
version: ^1.1.4
testImport:
- package: github.com/buger/jsonparser
- package: github.com/stretchr/testify
version: ^1.1.4
subpackages:
- assert
- package: gopkg.in/appleboy/gofight.v1
version: ^2.0.0

0 comments on commit 25c1ff7

Please sign in to comment.