login

package module
v0.0.0-...-1ad63a3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 6 Imported by: 1

README

login

Lightweight SSO Login System

Convention

  1. Redirect to login.changkun.de?redirect=origin
  2. When login success, login.changkun.de will redirect to origin with query parameter token=xxx
  3. A service provider should do:
    1. Post the token to login.changkun.de/verify to verify if the token is a valid token or not. If the token is not valid, do nothing.
    2. If the token is valid, then authentication success, and set cookie to the user.
    3. Later request to the service provider will have the cookie with the token, each time should verify the token is valid or not internally. If valid, authorize success. If not, redirect to login.changkun.de?redir=origin.

Test page

/test

License

Copyright (c) 2021 Changkun Ou. All Rights Reserved. Unauthorized using, copying, modifying and distributing,via any medium is strictly prohibited.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AuthEndpoint is the login authorization endpoint.
	AuthEndpoint = "https://login.changkun.de/auth"
	// VerifyEndpoint is the login verify endpoint.
	VerifyEndpoint = "https://login.changkun.de/verify"
)
View Source
var (
	ErrBadRequest   = errors.New("bad request")
	ErrUnauthorized = errors.New("unauthorized login")
)

Functions

func HandleAuth

func HandleAuth(w http.ResponseWriter, r *http.Request) (string, error)

Handle handles authentication by checking either query parameters regarding token or cookie auth.

func RequestToken

func RequestToken(user, pass string) (string, error)

RequestToken requests the login endpoint and returns the token for login.

func Verify

func Verify(token string) (string, error)

Verify checks if the given login token is valid or not.

Types

This section is empty.

Directories

Path Synopsis
cmd
This program initializes a bbolt database for the void.
This program initializes a bbolt database for the void.
internal

Jump to

Keyboard shortcuts

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