JWT middleware usage example
Would it be possible to have example of how to use JWT middleware ? CORS was quite easy and there are docs on the site but I can't get my head around how you use JWT
Thanks for raising this, here is an example until docs get added:
spec := &jwt.Specification{
AllowParam: false,
AuthOptions: false,
TTLMinutes: 1440,
Issuer: "api.xordataexchange.com",
KeySigningMethod: jwt.RSA256,
SigningKeyFunc: privateKey,
ValidationFunc: pubKey,
}
service.Use(jwt.Middleware(spec))
tm := jwt.NewTokenManager(spec)
You can then use tm to create tokens. Obviously this is just an example, your code may be organized differently.
I presume service.Use(jwt.Middleware(spec)) will wrap all API endpoints in jwt and would require token. How would I exclude i.e. /auth/login which would be used for authenticating and then generating tokens for client?
That's correct. You can mount middlewares on specific controllers instead of service wide.
Brilliant thanks ! BTW great project !
Thank you! I'll leave this issue opened until we have proper docs for the JWT middleware.
The package is now properly documented. Thanks for the report.