golaraauth

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

Golaraauth

golaraauth is a simple authentication provider written in GO used in Laravel 5.1+.

with this package you can verify the token string that generated by laravel and return the user model that used in laravel auth provider.

Installation

go get github.com/stremovskyy/golaraauth

Usage

laravel model

first of all you need to create a model that used in laravel with auth provider

package main

type DBModel struct {
    ID        int64
    TokenID   string
    CreatedAt string
    UpdatedAt string
}

this model will be used in the VerifyTokenString method to return the user model

package main

import (
    "fmt"
    "github.com/stremovskyy/golaraauth"
)


type DBModel struct {
	ID        int64
	TokenID   string
	CreatedAt string
	UpdatedAt string
}

func main() {
	model := &DBModel{}

	dbConfig := golaraauth.DbConfig{
		HostName:       "127.0.0.1",
		Port:           "3306",
		Username:       "root",
		Password:       "123698741",
		DbName:         "123456",
		TokensTable:    "user_tokens",
		TokensTableCol: "token_id",
	}

	config := golaraauth.AuthConfig{
		DbConfig:   dbConfig,
		PrivateKey: privKey,
		PublicKey:  pubkey,
	}

	a := golaraauth.LaravelAuthenticator{}
	err := a.New(config)
	if err != nil {
		panic(err)
	}

	defer a.CloseDBConnection()

	b, err := a.VerifyTokenString(tokenString, model)
	if err != nil {
		panic(err)
	}

	println(b)
}

License

MIT

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Authors

Acknowledgements

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	DbConfig       DbConfig
	PrivateKeyFile string
	PublicKeyFile  string
	PrivateKey     string
	PublicKey      string
}

type Authenticator

type Authenticator interface {
	New(config AuthConfig) error

	CloseDBConnection()

	VerifyTokenString(tokenString string, dbModel interface{}) (bool, error)
	// contains filtered or unexported methods
}

type DbConfig

type DbConfig struct {
	HostName       string
	Port           string
	Username       string
	Password       string
	DbName         string
	TokensTable    string
	TokensTableCol string
}

type LaravelAuthenticator

type LaravelAuthenticator struct {
	Token  *jwt.Token
	Config AuthConfig
	// contains filtered or unexported fields
}

func (*LaravelAuthenticator) CloseDBConnection

func (g *LaravelAuthenticator) CloseDBConnection()

func (*LaravelAuthenticator) New

func (g *LaravelAuthenticator) New(config AuthConfig) error

func (*LaravelAuthenticator) VerifyTokenString

func (g *LaravelAuthenticator) VerifyTokenString(tokenString string, dbModel interface{}) (bool, error)

VerifyTokenString verifies token string and puts Token object into structure

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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