pub struct Authenticator(/* private fields */);Expand description
Signs in to ChatGPT and keeps the stored credential fresh. Clones share the store and the refresh lock.
Implementations§
Source§impl Authenticator
impl Authenticator
Sourcepub async fn sign_in<H, F>(
&self,
http: &H,
method: SignInMethod,
prompt: F,
) -> Result<AuthContext, AuthError>
Available on non-target_family=wasm only.
pub async fn sign_in<H, F>( &self, http: &H, method: SignInMethod, prompt: F, ) -> Result<AuthContext, AuthError>
target_family=wasm only.Sign in again by method, whatever is cached, telling prompt what
the user must do. A browser sign-in whose callback ports are taken
says so and falls back to the device code. The credential is kept in
the token store. Native only.
Sourcepub async fn sign_in_with_device_code<H>(
&self,
http: &H,
) -> Result<AuthContext, AuthError>where
H: HttpClientExt,
Available on non-target_family=wasm only.
pub async fn sign_in_with_device_code<H>(
&self,
http: &H,
) -> Result<AuthContext, AuthError>where
H: HttpClientExt,
target_family=wasm only.Sign in again with the device-code flow, whatever is cached: the handler shows the code to enter, and the credential is kept in the token store. Native only.
Sourcepub async fn sign_in_with_browser<H, F>(
&self,
http: &H,
prompt: F,
) -> Result<AuthContext, AuthError>
Available on non-target_family=wasm only.
pub async fn sign_in_with_browser<H, F>( &self, http: &H, prompt: F, ) -> Result<AuthContext, AuthError>
target_family=wasm only.Sign in again in the browser, whatever is cached: an authorization
code with PKCE, returned to a one-shot listener on 127.0.0.1 port
1455, or 1457 when that is taken. The default browser is opened on
the sign-in page and prompt receives its URL, for the user to open
when the browser did not. The credential is kept in the token store.
Native only.
When both ports are taken, fails with AuthError::Io of kind
std::io::ErrorKind::AddrInUse, before prompting, so the caller can
fall back to Self::sign_in_with_device_code. Gives up after 15
minutes. Dropping the future stops the listener within a fraction of
a second and frees its port.
Sourcepub async fn sign_out<H>(&self, http: &H) -> Result<SignedOut, AuthError>where
H: HttpClientExt,
Available on non-target_family=wasm only.
pub async fn sign_out<H>(&self, http: &H) -> Result<SignedOut, AuthError>where
H: HttpClientExt,
target_family=wasm only.Sign out: the provider revokes the stored refresh token and access token, then the record is deleted from the store and forgotten here, whether or not the provider confirmed. Native only.
§Errors
When the store cannot be read, or the record cannot be deleted. A
revocation that failed is not an error: SignedOut::Forgotten
says why.
Source§impl Authenticator
impl Authenticator
Sourcepub fn new(
source: AuthSource,
store: impl TokenStore + 'static,
device_code_handler: DeviceCodeHandler,
allow_device_flow: bool,
) -> Self
pub fn new( source: AuthSource, store: impl TokenStore + 'static, device_code_handler: DeviceCodeHandler, allow_device_flow: bool, ) -> Self
An authenticator over source, keeping an OAuth sign-in in store
under PROVIDER_NAME, chatgpt;
device_code_handler shows a device code when the device flow is
allowed.
Sourcepub fn forget(&self)
pub fn forget(&self)
Forget the credential held in memory, so the next request reads the store: after the store’s record is deleted, as a sign-out does.
Sourcepub fn with_device_code_handler(self, handler: DeviceCodeHandler) -> Self
pub fn with_device_code_handler(self, handler: DeviceCodeHandler) -> Self
This authenticator showing device codes with handler, still
sharing its store and refresh lock with the original.
Sourcepub async fn auth_context<H>(&self, http: &H) -> Result<AuthContext, AuthError>where
H: HttpClientExt,
pub async fn auth_context<H>(&self, http: &H) -> Result<AuthContext, AuthError>where
H: HttpClientExt,
Resolve the access token and account id, refreshing through http as needed.
Return cache, transport, or authorization errors. OAuth is unsupported
on WASM; explicit access tokens remain available.
Trait Implementations§
Source§impl Clone for Authenticator
impl Clone for Authenticator
Source§impl CredentialSource for Authenticator
impl CredentialSource for Authenticator
Source§fn auth_context(
&self,
http: &DynHttpClient,
) -> impl Future<Output = Result<AuthContext, AuthError>> + WasmCompatSend
fn auth_context( &self, http: &DynHttpClient, ) -> impl Future<Output = Result<AuthContext, AuthError>> + WasmCompatSend
http when it
has expired.Auto Trait Implementations§
impl !RefUnwindSafe for Authenticator
impl !UnwindSafe for Authenticator
impl Freeze for Authenticator
impl Send for Authenticator
impl Sync for Authenticator
impl Unpin for Authenticator
impl UnsafeUnpin for Authenticator
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
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> ⓘ
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> ⓘ
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