oauth2

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package oauth2 contains the domain concept definitions needed to support Magistrala ui service OAuth2 functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ClientID     string `env:"CLIENT_ID"       envDefault:""`
	ClientSecret string `env:"CLIENT_SECRET"   envDefault:""`
	State        string `env:"STATE"           envDefault:""`
	RedirectURL  string `env:"REDIRECT_URL"    envDefault:""`
}

Config is the configuration for the OAuth2 provider.

type Provider

type Provider interface {
	// Name returns the name of the OAuth2 provider.
	Name() string

	// State returns the current state for the OAuth2 flow.
	State() string

	// RedirectURL returns the URL to redirect the user to after completing the OAuth2 flow.
	RedirectURL() string

	// ErrorURL returns the URL to redirect the user to in case of an error during the OAuth2 flow.
	ErrorURL() string

	// IsEnabled checks if the OAuth2 provider is enabled.
	IsEnabled() bool

	// Exchange converts an authorization code into a token.
	Exchange(ctx context.Context, code string) (oauth2.Token, error)

	// UserInfo retrieves the user's information using the access token.
	UserInfo(accessToken string) (mfclients.Client, error)
}

Provider is an interface that provides the OAuth2 flow for a specific provider (e.g. Google, GitHub, etc.)

type State

type State uint8

State is the state of the OAuth2 flow.

const (
	// SignIn is the state for the sign-in flow.
	SignIn State = iota
	// SignUp is the state for the sign-up flow.
	SignUp
)

func ToState

func ToState(state string) (State, error)

ToState converts string value to a valid OAuth2 state.

func (State) String

func (s State) String() string

Directories

Path Synopsis
Package google contains the domain concept definitions needed to support Magistrala services for Google OAuth2 functionality.
Package google contains the domain concept definitions needed to support Magistrala services for Google OAuth2 functionality.

Jump to

Keyboard shortcuts

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