login

package
v0.0.0-...-2f199bb Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package login contains methods for obtaining structure of the user data and its validation.

Index

Constants

View Source
const (
	KeyAuthDate  = "auth_date"
	KeyFirstName = "first_name"
	KeyHash      = "hash"
	KeyID        = "id"
	KeyLastName  = "last_name"
	KeyPhotoURL  = "photo_url"
	KeyUsername  = "username"
)

Key... represents available and supported data keys

Variables

View Source
var ErrUserNotDefined = errors.New("user is not defined")

ErrUserNotDefined describes error of an unassigned structure of user

Functions

This section is empty.

Types

type App

type App struct {
	SecretKey string
}

App represents a widget which get and validate users authorizations.

func New

func New(botToken string) *App

New create new app widget for validate authorizations with bot token as secret key.

func (*App) CheckAuthorization

func (app *App) CheckAuthorization(user *User) (bool, error)

CheckAuthorization verify the authentication and the integrity of the data received by comparing the received hash parameter with the hexadecimal representation of the HMAC-SHA-256 signature of the data-check-string with the SHA256 hash of the bot's token used as a secret key.

type User

type User struct {
	AuthDate  int64  `json:"auth_date"`
	FirstName string `json:"first_name"`
	Hash      string `json:"hash"`
	ID        int    `json:"id"`
	LastName  string `json:"last_name,omitempty"`
	PhotoURL  string `json:"photo_url,omitempty"`
	Username  string `json:"username,omitempty"`
}

User contains data about authenticated user.

func ParseUser

func ParseUser(src url.Values) (*User, error)

ParseUser create User structure from input url.Values.

func (*User) AuthTime

func (user *User) AuthTime() time.Time

AuthTime convert AuthDate field into time.Time.

func (*User) FullName

func (user *User) FullName() string

FullName return user first name only or full name if last name is present.

Jump to

Keyboard shortcuts

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