Documentation
¶
Index ¶
- func GenerateOAuthLink(provider, id, redirectURL, next string) string
- func GetFacebookAccessToken(redirectURL, code string) (string, error)
- func GetGithubAccessToken(code string) (string, error)
- type Action
- type FacebookProfile
- type FacebookToken
- type FacebookTokenJSON
- type GithubToken
- type GithubTokenJSON
- type GithubTokenSource
- type OAuthState
- type Picture
- type Profile
- type ProviderConfig
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateOAuthLink ¶
GenerateOAuthLink generates an OAuth link for the specified provider.
func GetFacebookAccessToken ¶
GetFacebookAccessToken retrieves the Facebook access token using the provided authorization code.
func GetGithubAccessToken ¶
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.
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 ¶
GetFacebookProfile retrieves the user's Facebook profile using the provided access token.
func GetGithubProfile ¶
GetGithubProfile retrieves the user's GitHub profile using the provided access token.
func GetOAuthProfile ¶
GetOAuthProfile retrieves the user's profile using the provided access token.
type ProviderConfig ¶
ProviderConfig holds the configuration for each OAuth provider.