Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix jwt-go v3 claim handling and react history + missing data key error #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.DS_Store
backend/gin-bin
node_modules
/backend/backend.iml
/.idea/
/dist/bundle.js
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
> This Fork works with actual jwt-go v3.0 (https://github.com/dgrijalva/jwt-go/blob/master/MIGRATION_GUIDE.md)
> and without gin

This repo is a demonstration / sketch for a react+redux frontend with a golang API backend that demonstrates:

* Use of higher-level components to protect pages in the frontend that require authorization
Expand All @@ -24,8 +27,9 @@ If there is interest, I'll make another post / video with more detail on how thi
First, you need a working Golang environment (1.5+)
* Clone the repo
* `npm install`
* `npm run frontend`
* `go get` to download the go packages
* `cd backend && go get` to download the go packages
* `go run main.go`
* `cd .. && npm run frontend` (in other terminal)

Open your browser to `localhost:8000/dist`

Expand Down
9 changes: 5 additions & 4 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ func GetCredentials(env *handler.Env, username, password string) Creds {
// Create the token
token := jwt.New(jwt.SigningMethodHS256)
// Set some claims
token.Claims["sub"] = username
token.Claims["iss"] = "example.com"
token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
claims := token.Claims.(jwt.MapClaims)
claims["sub"] = username
claims["iss"] = "example.com"
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
var err error
credentials.AuthToken, err = token.SignedString([]byte(env.Secret))
if err != nil {
Expand Down Expand Up @@ -148,7 +149,7 @@ func main() {
//This returns some fake data
r.Handle("/data", handler.Handler{env, FakeData}).Methods("GET", "OPTIONS")

port := "3001" // this is the gin port, but the app port is exposed at 3000
port := "3000" // this is the gin port, but the app port is exposed at 3000
http.ListenAndServe(":"+port, r)

}
Loading