pub struct OAuth2Config {
pub client_id: String,
pub client_secret: String,
pub redirect_url: String,
pub auth_url: String,
pub token_url: String,
pub user_url: Option<String>,
pub scopes: Vec<String>,
pub extra_params: Vec<(String, String)>,
}Expand description
OAuth2 配置 — 对齐 Laravel Socialite config/services.php
通过 builder 模式构建,必填字段在 OAuth2Config::new 中提供,
可选字段通过 with_* 链式方法追加。
§PHP 对齐
// config/services.php
'qq' => [
'client_id' => env('QQ_CLIENT_ID'),
'client_secret' => env('QQ_CLIENT_SECRET'),
'redirect' => env('QQ_REDIRECT_URL'),
],§Rust 用法
ⓘ
use sz_rust_auth_facade::oauth::OAuth2Config;
let config = OAuth2Config::new(
"100123456",
"secretabc",
"https://example.com/oauth/qq/callback",
"https://graph.qq.com/oauth2.0/authorize",
"https://graph.qq.com/oauth2.0/token",
)
.with_user_url("https://graph.qq.com/user/get_user_info")
.with_scope("get_user_info");Fields§
§client_id: String客户端 ID(必填)
client_secret: String客户端密钥(必填)
redirect_url: String回调 URL(必填)
auth_url: String授权服务器 authorize 端点(必填,如 https://graph.qq.com/oauth2.0/authorize)
token_url: String授权服务器 token 端点(必填,如 https://graph.qq.com/oauth2.0/token)
user_url: Option<String>资源服务器用户信息端点(可选,如 https://graph.qq.com/user/get_user_info)
scopes: Vec<String>默认 scopes(可选)
extra_params: Vec<(String, String)>额外参数(可选)
Implementations§
Source§impl OAuth2Config
impl OAuth2Config
Sourcepub fn new(
client_id: impl Into<String>,
client_secret: impl Into<String>,
redirect_url: impl Into<String>,
auth_url: impl Into<String>,
token_url: impl Into<String>,
) -> OAuth2Config
pub fn new( client_id: impl Into<String>, client_secret: impl Into<String>, redirect_url: impl Into<String>, auth_url: impl Into<String>, token_url: impl Into<String>, ) -> OAuth2Config
创建 OAuth2 配置
§参数
client_id: 客户端 IDclient_secret: 客户端密钥redirect_url: 回调 URLauth_url: 授权服务器 authorize 端点token_url: 授权服务器 token 端点
Sourcepub fn with_user_url(self, user_url: impl Into<String>) -> OAuth2Config
pub fn with_user_url(self, user_url: impl Into<String>) -> OAuth2Config
设置用户信息端点
Sourcepub fn with_scopes(self, scopes: Vec<String>) -> OAuth2Config
pub fn with_scopes(self, scopes: Vec<String>) -> OAuth2Config
设置 scopes 列表(覆盖原有)
Sourcepub fn with_scope(self, scope: impl Into<String>) -> OAuth2Config
pub fn with_scope(self, scope: impl Into<String>) -> OAuth2Config
追加单个 scope
Sourcepub fn with_extra_params(self, params: Vec<(String, String)>) -> OAuth2Config
pub fn with_extra_params(self, params: Vec<(String, String)>) -> OAuth2Config
设置额外参数列表(覆盖原有)
Sourcepub fn with_extra_param(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> OAuth2Config
pub fn with_extra_param( self, key: impl Into<String>, value: impl Into<String>, ) -> OAuth2Config
追加单个额外参数
Sourcepub fn validate(&self) -> Result<(), OAuth2Error>
pub fn validate(&self) -> Result<(), OAuth2Error>
校验必填字段
必填字段:client_id / client_secret / redirect_url / auth_url / token_url。
任一为空字符串则返回 OAuth2Error::MissingField。
Trait Implementations§
Source§impl Clone for OAuth2Config
impl Clone for OAuth2Config
Source§fn clone(&self) -> OAuth2Config
fn clone(&self) -> OAuth2Config
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for OAuth2Config
impl RefUnwindSafe for OAuth2Config
impl Send for OAuth2Config
impl Sync for OAuth2Config
impl Unpin for OAuth2Config
impl UnsafeUnpin for OAuth2Config
impl UnwindSafe for OAuth2Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.