Skip to main content

AuthorizeUrl

Struct AuthorizeUrl 

Source
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

Source

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).

Source

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.

Source

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).

Source

pub fn scopes(self, scopes: impl IntoIterator<Item = Scope>) -> Self

Adds scopes to request.

discord.js counterpart: the scopes option of Client#generateInvite.

Source

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).

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn build(&self) -> String

Returns the URL.

discord.js counterpart: Client#generateInvite.

Trait Implementations§

Source§

impl Clone for AuthorizeUrl

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AuthorizeUrl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for AuthorizeUrl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for AuthorizeUrl

Source§

impl PartialEq for AuthorizeUrl

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AuthorizeUrl

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToCompactString for T
where T: Display,

§

fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>

Fallible version of [ToCompactString::to_compact_string()] Read more
§

fn to_compact_string(&self) -> CompactString

Converts the given value to a [CompactString]. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more