Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
CasdoorEndpoint string // Base URL of your Casdoor instance (e.g., "https://door.casdoor.com")
ClientID string // The Client ID of your Casdoor application
Scope string // The scopes you are requesting (e.g., "openid profile email")
HttpClient *http.Client
// Optional endpoint paths. If not provided, default Casdoor paths will be used.
DeviceAuthPath string // The path for the device authorization endpoint. Defaults to "/api/device-auth".
TokenPath string // The path for the token endpoint. Defaults to "/api/login/oauth/access_token".
}
Config holds the necessary configuration for the device flow.
type DeviceAuthResponse ¶
type DeviceAuthResponse struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
DeviceAuthResponse is the response from the device authorization endpoint.
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
Scope string `json:"scope"`
IdToken string `json:"id_token"`
}
TokenResponse contains the tokens returned upon successful authorization.
func Authenticate ¶
func Authenticate(config Config, displayFunc func(authInfo *DeviceAuthResponse)) (*TokenResponse, error)
Authenticate orchestrates the entire device flow. It initiates the flow, calls the provided `displayFunc` to instruct the user, and then polls for the token until it's granted, an error occurs, or it times out.
func RefreshToken ¶
func RefreshToken(config Config, refreshToken string) (*TokenResponse, error)
RefreshToken uses a refresh token to obtain a new access and refresh token.
Click to show internal directories.
Click to hide internal directories.