oauth

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateOAuthLink(provider, id, redirectURL, next string) string

GenerateOAuthLink generates an OAuth link for the specified provider.

func GetFacebookAccessToken

func GetFacebookAccessToken(redirectURL, code string) (string, error)

GetFacebookAccessToken retrieves the Facebook access token using the provided authorization code.

func GetGithubAccessToken

func GetGithubAccessToken(code string) (string, error)

GetGithubAccessToken retrieves the GitHub access token using the provided authorization code.

Types

type Action

type Action interface {
	Wechat() string
	QQ() string
	StackOverflow() string
	Github(id, redirectURL string) string
	Facebook(id, redirectURL string) string
	Google(id, redirectURL string) string
}

Action defines the methods required for OAuth actions for different providers.

type FacebookProfile

type FacebookProfile struct {
	ID      string  `json:"id"`
	Name    string  `json:"name"`
	Email   string  `json:"email"`
	Picture Picture `json:"picture"`
}

FacebookProfile represents a Facebook user profile.

type FacebookToken

type FacebookToken struct {
	AccessToken  string    `json:"access_token"`
	TokenType    string    `json:"token_type"`
	RefreshToken string    `json:"refresh_token"`
	Expiry       time.Time `json:"expiry"`
	Raw          any       `json:"raw"`
}

FacebookToken represents a Facebook OAuth token.

type FacebookTokenJSON

type FacebookTokenJSON struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int32  `json:"expires_in"`
}

FacebookTokenJSON is used for unmarshalling the JSON response from Facebook.

type GithubToken

type GithubToken struct {
	AccessToken  string
	TokenType    string
	RefreshToken string
	Expiry       time.Time
	Raw          any
}

GithubToken represents a GitHub OAuth token.

type GithubTokenJSON

type GithubTokenJSON struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int32  `json:"expires_in"`
}

GithubTokenJSON is used for unmarshalling the JSON response from GitHub.

type GithubTokenSource

type GithubTokenSource struct {
	AccessToken string `json:"access_token"`
}

GithubTokenSource defines the structure to hold the GitHub access token.

func (*GithubTokenSource) Token

func (t *GithubTokenSource) Token() (*oauth2.Token, error)

Token returns the OAuth2 token for the GitHub token source.

type OAuthState

type OAuthState struct {
	State
}

OAuthState contains the state and implements the Action interface.

func OAuth

func OAuth(provider, next string) *OAuthState

OAuth initializes a new OAuthState with the given parameters.

func (OAuthState) Facebook

func (s OAuthState) Facebook(id, redirectURL string) string

Facebook generates the OAuth URL for Facebook.

func (OAuthState) Github

func (s OAuthState) Github(id, redirectURL string) string

Github generates the OAuth URL for GitHub.

func (OAuthState) Google

func (s OAuthState) Google(id, redirectURL string) string

Google generates the OAuth URL for Google.

func (OAuthState) QQ

func (s OAuthState) QQ() string

QQ generates the OAuth URL for QQ (not implemented).

func (OAuthState) StackOverflow

func (s OAuthState) StackOverflow() string

StackOverflow generates the OAuth URL for StackOverflow (not implemented).

func (OAuthState) Wechat

func (s OAuthState) Wechat() string

Wechat generates the OAuth URL for WeChat (not implemented).

type Picture

type Picture struct {
	Data struct {
		Height       int    `json:"height"`
		IsSilhouette bool   `json:"is_silhouette"`
		URL          string `json:"url"`
		Width        int    `json:"width"`
	} `json:"data"`
}

Picture defines the structure for a Facebook profile picture.

type Profile

type Profile struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	Thumbnail string `json:"thumbnail"`
}

Profile represents the user profile information obtained from OAuth.

func GetFacebookProfile

func GetFacebookProfile(token string) (*Profile, error)

GetFacebookProfile retrieves the user's Facebook profile using the provided access token.

func GetGithubProfile

func GetGithubProfile(accessToken string) (*Profile, error)

GetGithubProfile retrieves the user's GitHub profile using the provided access token.

func GetOAuthProfile

func GetOAuthProfile(provider, accessToken string) (*Profile, error)

GetOAuthProfile retrieves the user's profile using the provided access token.

type ProviderConfig

type ProviderConfig struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
}

ProviderConfig holds the configuration for each OAuth provider.

type State

type State struct {
	Provider string `json:"provider"`
	Next     string `json:"next"`
}

State represents the OAuth state with provider and next URL information.

Jump to

Keyboard shortcuts

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