pub struct AuthorizeUrl { /* private fields */ }Expand description
Builds an authorization URL
(https://discord.com/oauth2/authorize?…) that adds a bot to a guild or asks a user to
authorize the application (D-133).
discord.js counterpart: Client#generateInvite (bot invites only).
§Examples
use djs_model::{
id::{ApplicationId, GuildId},
oauth2::Scope,
permissions::Permissions,
};
use djs_rest::oauth2::AuthorizeUrl;
let invite = AuthorizeUrl::bot(ApplicationId::new(157))
.scopes([Scope::ApplicationsCommands])
.permissions(Permissions::SEND_MESSAGES | Permissions::EMBED_LINKS)
.guild_id(GuildId::new(42))
.disable_guild_select(true);
assert_eq!(
invite.build(),
"https://discord.com/oauth2/authorize?client_id=157&scope=bot%20applications.commands\
&permissions=18432&guild_id=42&disable_guild_select=true"
);
let login = AuthorizeUrl::code(ApplicationId::new(157), "https://example.com/callback")
.scopes([Scope::Identify])
.state("xyz");
assert_eq!(
login.to_string(),
"https://discord.com/oauth2/authorize?response_type=code&client_id=157&scope=identify\
&state=xyz&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback"
);Implementations§
Source§impl AuthorizeUrl
impl AuthorizeUrl
Sourcepub const fn new(client_id: ApplicationId) -> Self
pub const fn new(client_id: ApplicationId) -> Self
A URL with only the client ID: Discord uses the application’s default install settings from the Developer Portal (unless scopes, an integration type or a redirect URI are added).
discord.js counterpart: RESTOAuth2AuthorizationQuery (discord-api-types).
Sourcepub fn bot(client_id: ApplicationId) -> Self
pub fn bot(client_id: ApplicationId) -> Self
A bot authorization
URL: the bot scope, which adds the bot to a guild the user picks. No redirect is
needed.
discord.js counterpart: Client#generateInvite.
Sourcepub fn code(client_id: ApplicationId, redirect_uri: impl Into<String>) -> Self
pub fn code(client_id: ApplicationId, redirect_uri: impl Into<String>) -> Self
An authorization code grant
URL: Discord redirects the user to redirect_uri (one registered for the application)
with a code to exchange with exchange_code.
discord.js counterpart: RESTOAuth2AuthorizationQuery (discord-api-types).
Sourcepub fn scopes(self, scopes: impl IntoIterator<Item = Scope>) -> Self
pub fn scopes(self, scopes: impl IntoIterator<Item = Scope>) -> Self
Adds scopes to request.
discord.js counterpart: the scopes option of Client#generateInvite.
Sourcepub fn state(self, state: impl Into<String>) -> Self
pub fn state(self, state: impl Into<String>) -> Self
Sets the state
that Discord sends back with the redirect: a value tied to the user’s session, which
protects against cross-site request forgery.
discord.js counterpart: the state of RESTOAuth2AuthorizationQuery (discord-api-types).
Sourcepub fn redirect_uri(self, redirect_uri: impl Into<String>) -> Self
pub fn redirect_uri(self, redirect_uri: impl Into<String>) -> Self
Sets where Discord redirects the user after the authorization.
discord.js counterpart: the redirect_uri of RESTOAuth2AuthorizationQuery (discord-api-types).
Sourcepub const fn prompt(self, prompt: Prompt) -> Self
pub const fn prompt(self, prompt: Prompt) -> Self
Sets how a user who already authorized the scopes is treated.
discord.js counterpart: the prompt of RESTOAuth2AuthorizationQuery (discord-api-types).
Sourcepub const fn permissions(self, permissions: Permissions) -> Self
pub const fn permissions(self, permissions: Permissions) -> Self
Sets the permissions requested for the bot (with the bot scope).
discord.js counterpart: the permissions option of Client#generateInvite.
Sourcepub const fn guild_id(self, guild_id: GuildId) -> Self
pub const fn guild_id(self, guild_id: GuildId) -> Self
Preselects a guild in the guild picker (with the bot scope).
discord.js counterpart: the guild option of Client#generateInvite.
Sourcepub const fn disable_guild_select(self, disable: bool) -> Self
pub const fn disable_guild_select(self, disable: bool) -> Self
Whether the user may not pick another guild than guild_id.
discord.js counterpart: the disableGuildSelect option of Client#generateInvite.
Sourcepub const fn integration_type(self, integration_type: IntegrationType) -> Self
pub const fn integration_type(self, integration_type: IntegrationType) -> Self
Sets where the application is installed: in a guild or for the user (only relevant
with the applications.commands scope).
discord.js counterpart: the integration_type of RESTOAuth2AuthorizationQuery (discord-api-types).
Trait Implementations§
Source§impl Clone for AuthorizeUrl
impl Clone for AuthorizeUrl
Source§impl Debug for AuthorizeUrl
impl Debug for AuthorizeUrl
Source§impl Display for AuthorizeUrl
impl Display for AuthorizeUrl
impl Eq for AuthorizeUrl
Source§impl PartialEq for AuthorizeUrl
impl PartialEq for AuthorizeUrl
impl StructuralPartialEq for AuthorizeUrl
Auto Trait Implementations§
impl Freeze for AuthorizeUrl
impl RefUnwindSafe for AuthorizeUrl
impl Send for AuthorizeUrl
impl Sync for AuthorizeUrl
impl Unpin for AuthorizeUrl
impl UnsafeUnpin for AuthorizeUrl
impl UnwindSafe for AuthorizeUrl
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more