pub struct BrowserSession { /* private fields */ }Expand description
浏览器刷新会话 Cookie 能力:Cookie 名称与 Path 作用域参数化。
Implementations§
Source§impl BrowserSession
impl BrowserSession
Sourcepub fn new(
cookie_name: impl Into<String>,
cookie_path: impl Into<String>,
) -> Self
pub fn new( cookie_name: impl Into<String>, cookie_path: impl Into<String>, ) -> Self
用 Cookie 名称与 Path 作用域创建会话能力。
Sourcepub fn refresh_token(&self, request: &Request) -> Result<String, BaseError>
pub fn refresh_token(&self, request: &Request) -> Result<String, BaseError>
从请求 Cookie 头提取 Refresh Token;缺失或为空返回 Unauthorized。
Sourcepub fn validate_same_origin(request: &Request) -> Result<bool, BaseError>
pub fn validate_same_origin(request: &Request) -> Result<bool, BaseError>
校验变更类请求来自同源页面;返回请求是否经 HTTPS(用于 Cookie Secure 属性)。
非浏览器客户端通常没有 Origin/Referer;Cookie 不会被浏览器自动附带,
因而不具备跨站请求伪造条件,此时返回 Ok(false)。
Sourcepub fn token_response(
&self,
access_token: String,
refresh_token: String,
secure: bool,
) -> Result<ApiResponse, BaseError>
pub fn token_response( &self, access_token: String, refresh_token: String, secure: bool, ) -> Result<ApiResponse, BaseError>
构造会话建立响应:Access Token 进响应体,Refresh Token 进 HttpOnly Cookie。
Sourcepub fn clear_response(
&self,
response: ApiResponse,
secure: bool,
) -> Result<ApiResponse, BaseError>
pub fn clear_response( &self, response: ApiResponse, secure: bool, ) -> Result<ApiResponse, BaseError>
为已有响应追加清除会话 Cookie 的头。
Sourcepub fn relogin_response(
&self,
message: &str,
secure: bool,
) -> Result<ApiResponse, BaseError>
pub fn relogin_response( &self, message: &str, secure: bool, ) -> Result<ApiResponse, BaseError>
构造「请重新登录」响应并清除会话 Cookie。
Trait Implementations§
Source§impl Clone for BrowserSession
impl Clone for BrowserSession
Auto Trait Implementations§
impl Forget for BrowserSession
impl Freeze for BrowserSession
impl Move for BrowserSession
impl RefUnwindSafe for BrowserSession
impl Send for BrowserSession
impl Sync for BrowserSession
impl Unpin for BrowserSession
impl UnsafeUnpin for BrowserSession
impl UnwindSafe for BrowserSession
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
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 more