Documentation
ΒΆ
Index ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Config ΒΆ
type Config struct {
// ClientID is the Google OAuth2 client ID
ClientID string
// ClientSecret is the Google OAuth2 client secret
ClientSecret string
// RedirectURL is the callback URL for OAuth2 flow
// Either RedirectURL or RedirectPath must be provided
RedirectURL string
// RedirectPath is the callback path for OAuth2 flow (alternative to RedirectURL)
// When set, the absolute URL is generated dynamically from the request's scheme and host
// Example: "/auth/google/callback" becomes "https://example.com/auth/google/callback"
RedirectPath string
// TrustForwardedHeaders controls whether to trust X-Forwarded-* and Forwarded headers
// SECURITY: Only enable when behind a trusted proxy/load balancer that sets these headers
// Default: false (for security)
TrustForwardedHeaders bool
// AllowedRedirectHosts is an optional list of allowed hostnames for redirect URL generation
// When set, only these hosts are allowed when using RedirectPath
// Example: ["example.com", "staging.example.com", "localhost:8080"]
// Default: empty (allows any host - use with caution)
AllowedRedirectHosts []string
// AllowedHostedDomains is a list of Google Workspace domains allowed to authenticate
// Example: ["example.com", "company.org"]
AllowedHostedDomains []string
// Scopes are the OAuth2 scopes to request (default: openid, email, profile)
Scopes []string
// SessionCookieName is the name of the session cookie (default: "google_openid_session")
SessionCookieName string
// SessionMaxAge is the max age of the session cookie in seconds (default: 86400 = 24 hours)
SessionMaxAge int
// CookieSecure sets the Secure flag on cookies (should be true in production)
CookieSecure bool
// CookieHTTPOnly sets the HttpOnly flag on cookies (default: true)
CookieHTTPOnly bool
// CookieSameSite sets the SameSite attribute for cookies (default: Lax)
CookieSameSite http.SameSite
// LoginPath is the path where users initiate login (default: "/auth/google/login")
LoginPath string
// CallbackPath is the path for the OAuth2 callback (default: "/auth/google/callback")
CallbackPath string
// LogoutPath is the path for logout (default: "/auth/google/logout")
LogoutPath string
UnauthorizedHandler echo.HandlerFunc
// SuccessRedirect is the URL to redirect to after successful authentication
SuccessRedirect string
}
Config holds the configuration for the Google OpenID middleware
type Middleware ΒΆ
type Middleware struct {
// contains filtered or unexported fields
}
Middleware manages Google OpenID authentication
func New ΒΆ
func New(config *Config) (*Middleware, error)
New creates a new Google OpenID middleware with the given configuration
func (*Middleware) Protect ΒΆ
func (m *Middleware) Protect() echo.MiddlewareFunc
Protect returns an Echo middleware that requires authentication
func (*Middleware) RegisterRoutes ΒΆ
func (m *Middleware) RegisterRoutes(e *echo.Echo)
RegisterRoutes registers the authentication routes on the Echo instance
type UserInfo ΒΆ
type UserInfo struct {
Sub string `json:"sub"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
Name string `json:"name"`
Picture string `json:"picture"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
HostedDomain string `json:"hd"` // Google Workspace domain
}
UserInfo represents the authenticated user's information
Click to show internal directories.
Click to hide internal directories.