Skip to main content

wae_authentication/oauth2/providers/
github.rs

1//! GitHub OAuth2 提供者配置
2
3use crate::oauth2::OAuth2ProviderConfig;
4
5/// GitHub OAuth2 端点
6const GITHUB_AUTH_URL: &str = "https://github.com/login/oauth/authorize";
7const GITHUB_TOKEN_URL: &str = "https://github.com/login/oauth/access_token";
8const GITHUB_USERINFO_URL: &str = "https://api.github.com/user";
9
10/// 创建 GitHub OAuth2 配置
11///
12/// # Arguments
13/// * `client_id` - GitHub 客户端 ID
14/// * `client_secret` - GitHub 客户端密钥
15/// * `redirect_uri` - 重定向 URI
16pub fn github_config(
17    client_id: impl Into<String>,
18    client_secret: impl Into<String>,
19    redirect_uri: impl Into<String>,
20) -> OAuth2ProviderConfig {
21    OAuth2ProviderConfig::new("github", client_id, client_secret, redirect_uri)
22        .with_authorization_url(GITHUB_AUTH_URL)
23        .with_token_url(GITHUB_TOKEN_URL)
24        .with_userinfo_url(GITHUB_USERINFO_URL)
25        .with_scopes(vec!["user:email".to_string(), "read:user".to_string()])
26}
27
28/// GitHub OAuth2 默认范围
29pub fn github_default_scopes() -> Vec<String> {
30    vec!["user:email".to_string(), "read:user".to_string()]
31}
32
33/// GitHub OAuth2 只读范围
34pub fn github_readonly_scopes() -> Vec<String> {
35    vec!["read:user".to_string(), "user:email".to_string()]
36}
37
38/// GitHub OAuth2 完整范围
39pub fn github_full_scopes() -> Vec<String> {
40    vec!["user".to_string(), "user:email".to_string(), "repo".to_string(), "gist".to_string()]
41}