gae_authen

package module
v0.0.0-...-d934973 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2016 License: GPL-2.0 Imports: 7 Imported by: 0

README

Golang simple authentication module for Google App Engine

Installation

go get github.com/tianhai82/gae_authen

Note! Usage guide not updated!

Usage

import (
	"appengine"
	"github.com/tianhai82/gae_authen"
)
c := appengine.NewContext(r)

// Create new Authen instance
authen := NewAuthen(c, []byte("your 512 bits secret key"))

// create user
user, err := authen.CreateUser("testUser", []byte("P@ssw0rd"))

// try logging in
jwtTokenString, err = authen.Login("testUser", []byte("P@ssw0rd"))

// check whether user is still logged in (jwtTokenString is valid and not expired)
// will be called on every http request
// JWT token is implemented using https://github.com/dgrijalva/jwt-go
// to read claim values from the token, please read instruction at https://github.com/dgrijalva/jwt-go
jwtToken, err := authen.ParseToken(tokenString)

Documentation

Index

Constants

View Source
const AUTHEN = "_authen"

Variables

This section is empty.

Functions

This section is empty.

Types

type Authen

type Authen struct {
	// contains filtered or unexported fields
}

func NewAuthen

func NewAuthen(context appengine.Context, key []byte) *Authen

func (*Authen) ChangePassword

func (authen *Authen) ChangePassword(userid string, newPw []byte) bool

func (*Authen) ContainsUser

func (authen *Authen) ContainsUser(userid string) bool

func (*Authen) CreateUser

func (authen *Authen) CreateUser(userid string, username string, password []byte) (string, error)

func (*Authen) DeleteUsers

func (authen *Authen) DeleteUsers(userids []string) error

func (*Authen) GetCurrentUserId

func (authen *Authen) GetCurrentUserId(jwtCookie string) (string, error)

func (*Authen) Login

func (authen *Authen) Login(userid string, password []byte, duration int) (string, error)

func (*Authen) ParseToken

func (authen *Authen) ParseToken(tokenString string) (*jwt.Token, error)

func (*Authen) UpdateUser

func (authen *Authen) UpdateUser(userid string, username string) bool

type User

type User struct {
	Userid            string
	Username          string
	SaltedHash        []byte
	IsPasswordChanged bool
	Peep              []byte
}

type UserNotFound

type UserNotFound int

func (UserNotFound) Error

func (f UserNotFound) Error() string

type WrongPasswordError

type WrongPasswordError int

func (WrongPasswordError) Error

func (f WrongPasswordError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL