oauth

package
v0.0.0-...-674ef51 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TODO: make configurable (and used in the oauth handlers)
	AnilistServerBaseRUL     = "http://localhost:6969/oauth/al/"
	AnilistServerLoginURL    = AnilistServerBaseRUL + "login"
	AnilistServerCallbackURL = AnilistServerBaseRUL + "callback"
)
View Source
const (
	// TODO: make configurable (and used in the oauth handlers)
	MyAnimeListServerBaseRUL     = "http://localhost:6969/oauth/mal/"
	MyAnimeListServerLoginURL    = MyAnimeListServerBaseRUL + "login"
	MyAnimeListServerCallbackURL = MyAnimeListServerBaseRUL + "callback"
)

Variables

View Source
var (
	EmptyClientIDError        = Error("ClientID is empty")
	EmptyCodeError            = Error("Access Code/Token is empty")
	NilTokenError             = Error("Token is nil")
	TooManyCallbacksError     = Error("Too many callback requests")
	InvalidCallbackStateError = Error("Invalid callback state received")
)
View Source
var AnilistEndpoint = oauth2.Endpoint{
	AuthURL:   anilist.OAuthAuthorizeURL,
	TokenURL:  anilist.OAuthTokenURL,
	AuthStyle: oauth2.AuthStyleInParams,
}
View Source
var MyAnimeListEndpoint = oauth2.Endpoint{
	AuthURL:   myanimelist.OAuthAuthorizeURL,
	TokenURL:  myanimelist.OAuthTokenURL,
	AuthStyle: oauth2.AuthStyleInParams,
}

Functions

This section is empty.

Types

type AnilistLoginOption

type AnilistLoginOption struct {
	// ClientID is the application's ID.
	//
	// Must be non-empty.
	ClientID string

	// ClientSecret is the application's secret.
	//
	// When empty, the OAuth is an implicit grant.
	ClientSecret string
	// contains filtered or unexported fields
}

WARN: the implicit grant (empty ClientSecret) should be used with caution and only if completely needed, due to the access token being resent (to the same callback URL) on the URL params. Anilist api was designed to send it as part of the URL fragment, specifically so that servers didn't have access to the token directly.

AnilistLoginOption is an implementation of metadata.LoginOption that handles OAuth2 login.

func NewAnilistLoginOption

func NewAnilistLoginOption(clientID, clientSecret string) (*AnilistLoginOption, error)

func (*AnilistLoginOption) Authorize

func (o *AnilistLoginOption) Authorize(ctx context.Context) (tokenErr error)

Authorize will perform the authorization steps to obtain the oauth2 Token.

Anilist Oauth2 steps performed are:

1. Starting an http server to handle anilist callbacks with the access code/token. For more: https://anilist.gitbook.io/anilist-apiv2-docs/overview/oauth/getting-started#auth-pin

2. If doing a code grant (ClientSecret is not empty), converting the acces code to an access token. For more: https://anilist.gitbook.io/anilist-apiv2-docs/overview/oauth/authorization-code-grant#converting-authorization-codes-to-access-tokens

3. Retrieving (or generating in case of implicit grant) the oauth2 Token.

The http server lives for a max duration of 1 minute or until the access token is successfully retrieved/built.

func (*AnilistLoginOption) String

func (o *AnilistLoginOption) String() string

String the name of the login option, for logging purposes.

func (*AnilistLoginOption) Token

func (o *AnilistLoginOption) Token() *oauth2.Token

Token returns the authorization token (useful for caching).

type ConvertCodeError

type ConvertCodeError string

func (ConvertCodeError) Error

func (e ConvertCodeError) Error() string

type Error

type Error string

Error is used for generic OAuth errors.

func (Error) Error

func (e Error) Error() string

type MyAnimeListLoginOption

type MyAnimeListLoginOption struct {
	// ClientID is the application's ID.
	//
	// Must be non-empty.
	ClientID string

	// ClientSecret is the application's secret.
	//
	// Could be empty for "Other" App Types.
	ClientSecret string
	// contains filtered or unexported fields
}

MyAnimeListLoginOption is an implementation of metadata.LoginOption that handles OAuth2 login.

func NewMyAnimeListLoginOption

func NewMyAnimeListLoginOption(clientID, clientSecret string) (*MyAnimeListLoginOption, error)

func (*MyAnimeListLoginOption) Authorize

func (o *MyAnimeListLoginOption) Authorize(ctx context.Context) (tokenErr error)

Authorize will perform the authorization steps to obtain the oauth2 Token.

func (*MyAnimeListLoginOption) String

func (o *MyAnimeListLoginOption) String() string

String the name of the login option, for logging purposes.

func (*MyAnimeListLoginOption) Token

func (o *MyAnimeListLoginOption) Token() *oauth2.Token

Token returns the authorization token (useful for caching).

Jump to

Keyboard shortcuts

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