UNPKG

discord-authorize

Version:

A node module for easy authentication with Discord

97 lines 3.47 kB
import { OAuth2Options } from "../types"; import { Scopes, UserInfo, ConnectionType, Guild } from "../types"; import { snowflake } from "../global"; import { GuildJoinOptions } from "../types/Authorize"; /** * Represents an instance of Discord OAuth2 authorization flow. */ declare class DiscordAuthorization { private clientId; private clientSecret; private redirectUri; private accessToken; private baseURL; private refreshToken; private clientToken; /** * Creates an instance of DiscordAuthorization. * @param {OAuth2Options} options - Options for OAuth2 authorization. */ constructor(options: OAuth2Options); /** * Generates an OAuth2 authorization link for Discord. * @param {{ scopes: Scopes[] }} param0 - Authorization scopes array. * @param {string} [state="1bac472"] - Authorization state * @returns {string} - OAuth2 authorization link. */ generateOauth2Link({ scopes }: { scopes: Scopes[]; }, state?: string): string; /** * Exchanges an authorization code for access and refresh tokens. * @param {string} code - Authorization code. * @returns {Promise<object>} - Tokens object containing access and refresh tokens. * @throws {Error} - If the exchange process fails. */ exchangeCodeForTokens(code: string): Promise<{ accessToken: string; refreshToken: string; }>; /** * Sets the access token. * @param {string} token - The access token to set. */ setAccessToken(token: string): void; /** * Sets the refresh token. * @param {string} token - The refresh token to set. */ setRefreshToken(token: string): void; /** * Revokes the existinga ccess token */ refreshAccessToken(): Promise<void>; /** * Retrieves information about the authorized user. * @returns {Promise<UserInfo>} - User information. * @throws {Error} - If fetching user information fails. */ getMyInfo(): Promise<UserInfo>; /** * Retrieves connections of the authorized user. * @returns {Promise<ConnectionType[]>} - User connections information. * @throws {Error} - If fetching user connections fails. */ getMyConnections(): Promise<ConnectionType[]>; /** * Retrives joined guilds of the authorized user. * @returns {Promise<Guild[]>} - User guilds information */ getGuilds(): Promise<Guild[]>; /** * Get info of the bot. */ getApplication(): Error; /** * Joins a guild with the specified options. * @param {GuildJoinOptions} options - The options for joining the guild. * @returns {Promise<any>} A promise that resolves with the response data upon successful joining. * @throws {Error} If an error occurs during the join process. */ joinGuild(options: GuildJoinOptions): Promise<any>; getMyInfoFromGuild(guildId: snowflake): Promise<any>; /** * Retrieves the username of the authorized user. * @returns {Promise<string>} - User's username. * @throws {Error} - If fetching the username fails. */ getMyUsername(): Promise<string>; /** * Retrieves the email of the authorized user. * @returns {Promise<string>} - User's email. * @throws {Error} - If fetching the email fails. */ getMyEmail(): Promise<string>; } export { DiscordAuthorization, Scopes }; //# sourceMappingURL=authenticator.d.ts.map