auth

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: BSD-3-Clause Imports: 3 Imported by: 1

README

go-auth

user authorization verification module

Coverage Status Release Go Report Card CI

Install

go get -u github.com/deweppro/go-auth

Examples

see more here

Setup providers config
import (
    "github.com/deweppro/go-auth/config"
    "github.com/deweppro/go-auth/providers"
)

var providerConfig = &config.Config{
		Provider: []config.ConfigItem{
			{
				Code:         "google",
				ClientID:     "****************.apps.googleusercontent.com",
				ClientSecret: "****************",
				RedirectURL:  "https://example.com/oauth/callback/google",
			},
		},
	}

providers := providers.New(providerConfig)

You can add our provider corresponding to the providers.IProvider interface

providers.Add(provider1, provider2, ...)
Initializing the authorization service
import "github.com/deweppro/go-auth"

authServ := auth.New(providers)
Request Handlers

the methods return an http handler func(http.ResponseWriter, *http.Request) when called

Creating a redirect to the provider
// <provider name> - provider name from the config
authServ.Request(<provider name>)
Processing the provider's response
authServ.CallBack(<provider name>, <callback function>)
  • <provider name> - provider name from config
  • <callback function> - response results handler has signature func(http.ResponseWriter, *http.Request, isp.IUser)
    • isp.IUser - a new instance of the processed user model with ACL data filling

License

BSD-3-Clause License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

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

func New

func New(p providers.IProviders) *Auth

func (*Auth) CallBack

func (v *Auth) CallBack(name string, cb func(http.ResponseWriter, *http.Request, isp.IUser)) HttpHandler

func (*Auth) Request

func (v *Auth) Request(name string) HttpHandler

type HttpHandler

type HttpHandler func(http.ResponseWriter, *http.Request)

Directories

Path Synopsis
isp

Jump to

Keyboard shortcuts

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