Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
added godoc documentation for tokenauth usage (#1060)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivakishore14 authored and markbates committed Jul 4, 2018
1 parent 1ca7848 commit 311e2c4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions middleware/tokenauth/tokenauth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
// Package tokenauth provides jwt token authorisation middleware
// supports HMAC, RSA, ECDSA, RSAPSS algorithms
// uses github.com/dgrijalva/jwt-go for jwt implementation
//
// Setting Up tokenauth middleware
//
// Using tokenauth with defaults
// app.Use(tokenauth.New(tokenauth.Options{}))
// Specifying Signing method for JWT
// app.Use(tokenauth.New(tokenauth.Options{
// SignMethod: jwt.SigningMethodRS256,
// }))
// By default the Key used is loaded from the JWT_SECRET or JWT_PUBLIC_KEY env variable depending
// on the SigningMethod used. However you can retrive the key from a different source.
// app.Use(tokenauth.New(tokenauth.Options{
// GetKey: func(jwt.SigningMethod) (interface{}, error) {
// // Your Implementation here ...
// },
// }))
//
//
// Creating a new token
//
// This can be referred from the underlying JWT package being used https://github.com/dgrijalva/jwt-go
//
// Example
// claims := jwt.MapClaims{}
// claims["userid"] = "123"
// claims["exp"] = time.Now().Add(time.Minute * 5).Unix()
// // add more claims
// token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
// tokenString, err := token.SignedString([]byte(SecretKey))
//
//
// Getting Claims from JWT token from buffalo context
//
// Example of retriving username from claims (this step is same regardless of the signing method used)
// claims := c.Value("claims").(jwt.MapClaims)
// username := claims["username"].(string)
package tokenauth

import (
Expand Down

0 comments on commit 311e2c4

Please sign in to comment.