Adjust function names
This commit is contained in:
parent
b15c942e64
commit
29d8197ba3
5 changed files with 13 additions and 13 deletions
|
@ -15,7 +15,7 @@ func validEmail(email string) bool {
|
|||
return err == nil
|
||||
}
|
||||
func validPass(pass string) bool {
|
||||
// TODO: Obviously, we *might* want something more sophisticated here
|
||||
// Note: Obviously, we *might* want something more sophisticated here
|
||||
return len(pass) >= 8
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
token, err := Create(user)
|
||||
token, err := CreateToken(user)
|
||||
if err != nil {
|
||||
http.Error(w, "error creating jwt", http.StatusInternalServerError)
|
||||
return
|
||||
|
|
|
@ -66,7 +66,7 @@ func ServePublicKey(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Create creates a JSON Web Token that expires after a week
|
||||
func Create(user user.User) (token string, err error) {
|
||||
func CreateToken(user user.User) (token string, err error) {
|
||||
t := jwt.NewWithClaims(jwt.SigningMethodRS256,
|
||||
jwt.MapClaims{
|
||||
"iss": "pye",
|
||||
|
@ -85,7 +85,7 @@ func Create(user user.User) (token string, err error) {
|
|||
|
||||
// Verify receives a JWT and PEM-encoded public key,
|
||||
// then returns whether the token is valid
|
||||
func Verify(token string, publicKey []byte) (*jwt.Token, error) {
|
||||
func VerifyToken(token string, publicKey []byte) (*jwt.Token, error) {
|
||||
t, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) {
|
||||
key, err := jwt.ParseRSAPublicKeyFromPEM(publicKey)
|
||||
if err != nil {
|
||||
|
@ -100,8 +100,8 @@ func Verify(token string, publicKey []byte) (*jwt.Token, error) {
|
|||
}
|
||||
|
||||
// VerifyLocal calls Verify with public key set to current local one
|
||||
func VerifyLocal(token string) (*jwt.Token, error) {
|
||||
func VerifyLocalToken(token string) (*jwt.Token, error) {
|
||||
key_marshalled := x509.MarshalPKCS1PublicKey(&key.PublicKey)
|
||||
block := pem.Block{Bytes: key_marshalled, Type: "RSA PUBLIC KEY"}
|
||||
return Verify(token, pem.EncodeToMemory(&block))
|
||||
return VerifyToken(token, pem.EncodeToMemory(&block))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue