Skip to content

Commit

Permalink
added deps
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimti committed May 27, 2018
1 parent 8dafa39 commit a8e8c57
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Godeps/Godeps.json

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

3 changes: 2 additions & 1 deletion example_cfg.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Example configuration
port: 8888
debug: false
debug: true
encKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # 32-64 character string
remote: http://example.com
expHours: 1
getTokenRoute: "/getToken"
checkTokenRoute: "/checkToken"
requestTokenData:
authorization: "internal"
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"encoding/json"

jwt_lib "github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go/request"
"github.com/gin-contrib/zap"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
Expand All @@ -27,6 +28,7 @@ type config struct {
Remote string `yaml:"remote"`
ExpHours int64 `yaml:"expHours"`
GetTokenRoute string `yaml:"getTokenRoute"`
CheckTokenRoute string `yaml:"checkTokenRoute"`
RequestTokenData map[string]interface{} `yaml:"requestTokenData"`
}

Expand Down Expand Up @@ -76,9 +78,28 @@ func main() {
// Route get token request
r.POST(cfg.GetTokenRoute, tokenRouteHandler)

// Route check token request
r.GET(cfg.CheckTokenRoute, checkTokenRouteHandler)

r.Run(":" + cfg.Port)
}

func checkTokenRouteHandler(c *gin.Context) {
cfg := c.MustGet("Cfg").(config)

decoded, err := request.ParseFromRequest(c.Request, request.OAuth2Extractor, func(token *jwt_lib.Token) (interface{}, error) {
b := []byte(cfg.EncKey)
return b, nil
})

if err != nil {
c.JSON(401, gin.H{"error": err.Error()})
return
}

c.JSON(200, decoded)
}

// RouteHandler handles the http route for inbound data
func tokenRouteHandler(c *gin.Context) {
cfg := c.MustGet("Cfg").(config)
Expand Down
7 changes: 7 additions & 0 deletions vendor/github.com/dgrijalva/jwt-go/request/doc.go

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

81 changes: 81 additions & 0 deletions vendor/github.com/dgrijalva/jwt-go/request/extractor.go

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

28 changes: 28 additions & 0 deletions vendor/github.com/dgrijalva/jwt-go/request/oauth2.go

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

68 changes: 68 additions & 0 deletions vendor/github.com/dgrijalva/jwt-go/request/request.go

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

83 changes: 83 additions & 0 deletions vendor/github.com/gin-gonic/contrib/jwt/README.md

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

20 changes: 20 additions & 0 deletions vendor/github.com/gin-gonic/contrib/jwt/jwt.go

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

0 comments on commit a8e8c57

Please sign in to comment.