#[non_exhaustive]pub struct AccessTokenResponse {
pub access_token: String,
pub token_type: CompactString,
pub expires_in: u64,
pub refresh_token: Option<String>,
pub scope: CompactString,
pub guild: Option<Box<Guild>>,
pub webhook: Option<Box<Webhook>>,
}Expand description
The response of the token endpoint: an access token for the user who authorized the application.
Send it with a client built with RestBuilder::bearer_token to act for the user. The
tokens are redacted in the Debug output (C-011).
discord.js counterpart: none (discord-api-types: RESTPostOAuth2AccessTokenResult).
§Examples
use djs_model::oauth2::{AccessTokenResponse, Scope};
let response: AccessTokenResponse = serde_json::from_str(
r#"{"access_token": "user-access-token", "token_type": "Bearer",
"expires_in": 604800, "refresh_token": "user-refresh-token",
"scope": "identify guilds"}"#,
)?;
assert_eq!(
response.scopes().collect::<Vec<_>>(),
[Scope::Identify, Scope::Guilds]
);
assert!(!format!("{response:?}").contains("user-access-token"));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.access_token: StringThe access token.
token_type: CompactStringHow the token is sent (Bearer).
expires_in: u64How many seconds the access token is valid for.
refresh_token: Option<String>The token to get a new access token with once this one expires. Client credentials grants do not get one.
scope: CompactStringThe authorized scopes, separated by spaces; see scopes.
guild: Option<Box<Guild>>For the bot scope with the authorization code grant: the guild the bot was added
to.
webhook: Option<Box<Webhook>>For the webhook.incoming scope: the webhook created in the channel the user picked,
with its token.
Implementations§
Trait Implementations§
Source§impl Clone for AccessTokenResponse
impl Clone for AccessTokenResponse
Source§impl Debug for AccessTokenResponse
impl Debug for AccessTokenResponse
Source§impl<'de> Deserialize<'de> for AccessTokenResponse
impl<'de> Deserialize<'de> for AccessTokenResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for AccessTokenResponse
Source§impl PartialEq for AccessTokenResponse
impl PartialEq for AccessTokenResponse
Source§impl Serialize for AccessTokenResponse
impl Serialize for AccessTokenResponse
impl StructuralPartialEq for AccessTokenResponse
Auto Trait Implementations§
impl Forget for AccessTokenResponse
impl Freeze for AccessTokenResponse
impl Move for AccessTokenResponse
impl RefUnwindSafe for AccessTokenResponse
impl Send for AccessTokenResponse
impl Sync for AccessTokenResponse
impl Unpin for AccessTokenResponse
impl UnsafeUnpin for AccessTokenResponse
impl UnwindSafe for AccessTokenResponse
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