GithubHelp home page GithubHelp logo

golang-jwt-authentication-api-sample's People

Contributors

dghilardi avatar raul-diffindo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

golang-jwt-authentication-api-sample's Issues

Get public key from private key

In your jwt_backend.go you could retrieve the RSA public key part from the private key, because due to logic and the official GoDocs of rsa.PrivateKey the PublicKey is contained in the PrivateKey. This helps to avoid a lot of action.

Just a suggestion, because I use a similar backend in my current project:

// GetPublicKey returns the rsa public key from the private key
func GetPublicKey(privateKey *rsa.PrivateKey) *rsa.PublicKey {
    return &privateKey.PublicKey
}

Sorry I'm too lazy right now to create a pull request, nonetheless thanks for this project (and the regarding blog post), it helped a lot! ๐Ÿ‘ ๐Ÿ™‡

logout route

Hello,

If you are getting on logout Completed 500 Internal Server Error
add redis authentication

How can i run it?

Hello Author.
I cloned to $GOPATH/src and run go get and changed "code.google.com/p/go-uuid/uuid" to "github.com/pborman/uuid" but now ocurred errors

core/authentication/jwt_backend.go:44: invalid operation: token.Claims["exp"] (type jwt.Claims does not support indexing)
core/authentication/jwt_backend.go:45: invalid operation: token.Claims["iat"] (type jwt.Claims does not support indexing)
core/authentication/jwt_backend.go:46: invalid operation: token.Claims["sub"] (type jwt.Claims does not support indexing)
core/authentication/jwt_backend.go:80: invalid operation: token.Claims["exp"] (type jwt.Claims does not support indexing)
core/authentication/middlewares.go:12: undefined: jwt.ParseFromRequest

Many thanks.

paths

Changed the paths to relative in settings/pre, prod, testing.json so it finds the keys without vagrant.

a bug in middlewares.go allows unauthorized access

After an authenticated user has logged out, a malicious user can continue accessing his account if the malicious user gets his jwt token. To do so, instead of passing the jwt token in the HTTP header, the malicious user can just pass the token as a query argument "access_token".

request.OAuth2Extractor would retrieve jwt token from either HTTP header or "access_token" argument therefore a previously logged out token will be still validated. authBackend.IsInBlacklist() wouldn't block the access because req.Header.Get("Authorization") doesn't have the token.

func RequireTokenAuthentication(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
authBackend := InitJWTAuthenticationBackend()

** token, err := request.ParseFromRequest(req, request.OAuth2Extractor, func(token *jwt.Token) (interface{}, error) { **
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
} else {
return authBackend.PublicKey, nil
}
})

** if err == nil && token.Valid && !authBackend.**IsInBlacklist(req.Header.Get("Authorization")) { **
next(rw, req)
} else {
rw.WriteHeader(http.StatusUnauthorized)
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.