utils

package
v0.0.0-...-85b8e82 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CorsConfig = cors.New(cors.Options{
	AllowedOrigins: []string{
		"https://hello-slide.jp",
		"https://hello-slide.com",
		"https://hello-slide.net",
		"http://localhost:3000",
	},
	AllowCredentials: true,
})

Functions

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, statusCode int, err error)

func ErrorStatus

func ErrorStatus(w http.ResponseWriter)

Types

type CookieOperation

type CookieOperation struct {
	Path     string
	Domain   string
	Secure   bool
	HttpOnly bool
}

func NewCookieOp

func NewCookieOp(domain string) *CookieOperation

func (*CookieOperation) Delete

func (c *CookieOperation) Delete(w http.ResponseWriter, req *http.Request, name string) error

Delete cookie

Arguments:

w {http.ResponseWriter} - http writer.
req {http.Request} - http request.

name {string} - cookie key.

func (*CookieOperation) Get

func (c *CookieOperation) Get(req *http.Request, name string) (string, error)

Get cookie.

Arguments:

req {http.Request} - http request.
name {string} - cookie key.

Retruns:

{string} - cookie value.

func (*CookieOperation) Set

func (c *CookieOperation) Set(w http.ResponseWriter, name string, value string, exp int)

Set cookie.

Arguments:

w {http.ResponseWriter} - http writer.
name {string} - cookie key.
value {string} - cookie value.
exp {int} - date of expiry. It is an hourly unit.

type TokenOperation

type TokenOperation struct {
	CookieOp CookieOperation
}

func NewTokenOp

func NewTokenOp(apiUrl string) (*TokenOperation, error)

Create tokenOp.

Arguments;

apiUrl {string} - URL of the API you are using.

func (*TokenOperation) DeleteToken

func (t *TokenOperation) DeleteToken(w http.ResponseWriter, r *http.Request) error

Delete session and refresh tokens.

Arguments:

w {http.ResponseWriter} - http writer.
r {*http.Request} - http requests.

func (*TokenOperation) GetRefreshToken

func (t *TokenOperation) GetRefreshToken(r *http.Request) (string, error)

Get the refresh token.

Arguments:

r {*http.Request} - http requests.

Returns:

{string} - refresh token.

func (*TokenOperation) GetSessionToken

func (t *TokenOperation) GetSessionToken(r *http.Request) (string, error)

Get the session token.

Arguments:

r {*http.Request} - http requests.

Returns:

{string} - session token.

func (*TokenOperation) GetSessonTokenTrueRedirect

func (t *TokenOperation) GetSessonTokenTrueRedirect(
	ctx context.Context,
	w http.ResponseWriter,
	r *http.Request,
	tokenManageName string,
	apiUrl string,
	handlePath string) (string, error)

リフレッシュトークンを使用してログインします

func (*TokenOperation) SetRefreshToken

func (t *TokenOperation) SetRefreshToken(w http.ResponseWriter, refreshToken string)

Set the refresh token.

Arguments:

w {http.ResponseWriter} - http writer.
refreshToken {string} - refresh token.

func (*TokenOperation) SetSessionToken

func (t *TokenOperation) SetSessionToken(w http.ResponseWriter, sessionToken string)

Set the session token.

Arguments:

w {http.ResponseWriter} - http writer.
sessionToken {string} - session token.

Jump to

Keyboard shortcuts

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