egothic

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

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 9 Imported by: 1

README

                                          _   _      _
                         ___   __ _  ___ | |_| |__  (_) ___ 
                        / _ \ / _` |/ _ \| __| '_ \ | |/ __|
                       |  __/| (_| | (_) | |_| | | || | (__ 
                        \___| \__, |\___/ \__|_| |_||_|\___|
                              |___/                     

egothic

import "github.com/agentstation/egothic"

Package egothic is a modified version of original gothic package for the Echo server. The original gothic package is a wrapper for the Goth library. This package is based on https://github.com/markbates/goth/blob/edc3e96387cb58c3f3d58e70db2f115815ccdf1e/gothic/gothic.go

Index

Variables

GetProviderName is a function used to get the name of a provider for a given request. By default, this provider is fetched from the URL query string. If you provide it in a different way, assign your own function to this variable that returns the provider name for your request.

var GetProviderName = getProviderName

GetState gets the state returned by the provider during the callback. This is used to prevent CSRF attacks, see http://tools.ietf.org/html/rfc6749#section-10.12

var GetState = func(e echo.Context) string {
    return gothic.GetState(e.Request())
}

SetState sets the state string associated with the given request. If no state string is associated with the request, one will be generated. This state is sent to the provider and can be retrieved during the callback.

var SetState = func(e echo.Context) string {
    return gothic.SetState(e.Request())
}

func BeginAuthHandler

func BeginAuthHandler(e echo.Context, opts ...Options) error

BeginAuthHandler will redirect the user to the appropriate authentication end-point for the requested provider.

func CompleteUserAuth

func CompleteUserAuth(e echo.Context, opts ...Options) (goth.User, error)

It expects to be able to get the name of the provider from the query parameters as either "provider" or ":provider".

func GetAuthURL

func GetAuthURL(e echo.Context, opts ...Options) (string, error)

I would recommend using the BeginAuthHandler instead of doing all of these steps yourself, but that's entirely up to you.

func GetFromSession

func GetFromSession(e echo.Context, key string) (string, error)

GetFromSession retrieves a previously-stored value from the session. If no value has previously been stored at the specified key, it will return an error.

func Logout

func Logout(e echo.Context) error

Logout invalidates a user session.

func Redirect

func Redirect(e echo.Context, url string, opts ...Options) error

Redirect redirects the user to the given URL. This method attempts to avoid browser caching by setting appropriate headers. It attempts a server-side redirect first, and if that fails, it sends a page with JavaScript redirect.

func SetStore

func SetStore(store sessions.Store)

SetStore sets the store for the gothic session.

func Store

func Store() sessions.Store

Store returns the store for the gothic session.

func StoreInSession

func StoreInSession(e echo.Context, key string, value string) error

StoreInSession stores a specified key/value pair in the session.

type Options

Options is a function that configures the egothic package.

type Options func(*egothicConfig)

func WithDebug
func WithDebug() Options

WithDebug enables the debug mode for the egothic package.

func WithLogger
func WithLogger(logger *log.Logger) Options

WithLogger sets the logger for the egothic package.

Generated by gomarkdoc

Documentation

Overview

Package egothic is a modified version of original gothic package for the Echo server. The original gothic package is a wrapper for the Goth library. This package is based on https://github.com/markbates/goth/blob/edc3e96387cb58c3f3d58e70db2f115815ccdf1e/gothic/gothic.go

Index

Constants

This section is empty.

Variables

View Source
var GetProviderName = getProviderName

GetProviderName is a function used to get the name of a provider for a given request. By default, this provider is fetched from the URL query string. If you provide it in a different way, assign your own function to this variable that returns the provider name for your request.

View Source
var GetState = func(e echo.Context) string {
	return gothic.GetState(e.Request())
}

GetState gets the state returned by the provider during the callback. This is used to prevent CSRF attacks, see http://tools.ietf.org/html/rfc6749#section-10.12

View Source
var SetState = func(e echo.Context) string {
	return gothic.SetState(e.Request())
}

SetState sets the state string associated with the given request. If no state string is associated with the request, one will be generated. This state is sent to the provider and can be retrieved during the callback.

Functions

func BeginAuthHandler

func BeginAuthHandler(e echo.Context, opts ...Options) error

BeginAuthHandler will redirect the user to the appropriate authentication end-point for the requested provider.

func CompleteUserAuth

func CompleteUserAuth(e echo.Context, opts ...Options) (goth.User, error)

It expects to be able to get the name of the provider from the query parameters as either "provider" or ":provider".

func GetAuthURL

func GetAuthURL(e echo.Context, opts ...Options) (string, error)

I would recommend using the BeginAuthHandler instead of doing all of these steps yourself, but that's entirely up to you.

func GetFromSession

func GetFromSession(e echo.Context, key string) (string, error)

GetFromSession retrieves a previously-stored value from the session. If no value has previously been stored at the specified key, it will return an error.

func Logout

func Logout(e echo.Context) error

Logout invalidates a user session.

func Redirect

func Redirect(e echo.Context, url string, opts ...Options) error

Redirect redirects the user to the given URL. This method attempts to avoid browser caching by setting appropriate headers. It attempts a server-side redirect first, and if that fails, it sends a page with JavaScript redirect.

func SetStore

func SetStore(store sessions.Store)

SetStore sets the store for the gothic session.

func Store

func Store() sessions.Store

Store returns the store for the gothic session.

func StoreInSession

func StoreInSession(e echo.Context, key string, value string) error

StoreInSession stores a specified key/value pair in the session.

Types

type Options

type Options func(*egothicConfig)

Options is a function that configures the egothic package.

func WithDebug

func WithDebug() Options

WithDebug enables the debug mode for the egothic package.

func WithLogger

func WithLogger(logger *log.Logger) Options

WithLogger sets the logger for the egothic package.

Jump to

Keyboard shortcuts

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