From 61c1e060f965a25611a5ceca9eb83ff293d0e080 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 31 Mar 2021 17:25:09 +0200 Subject: [PATCH] types: add oauth2 types (#719) * add types * Update get_current_authorization_information.ts * Update src/types/oauth2/get_current_authorization_information.ts Co-authored-by: ayntee * Update src/types/oauth2/get_current_authorization_information.ts Co-authored-by: ayntee * Update bot_auth_query.ts * Update scopes.ts Co-authored-by: ayntee --- src/types/oauth2/application.ts | 40 +++++++++++++++++++ src/types/oauth2/bot_auth_query.ts | 20 ++++++++++ .../get_current_authorization_information.ts | 20 ++++++++++ src/types/oauth2/scopes.ts | 23 +++++++++++ 4 files changed, 103 insertions(+) create mode 100644 src/types/oauth2/application.ts create mode 100644 src/types/oauth2/bot_auth_query.ts create mode 100644 src/types/oauth2/get_current_authorization_information.ts create mode 100644 src/types/oauth2/scopes.ts diff --git a/src/types/oauth2/application.ts b/src/types/oauth2/application.ts new file mode 100644 index 000000000..b1ad592e6 --- /dev/null +++ b/src/types/oauth2/application.ts @@ -0,0 +1,40 @@ +import { User } from "../users/user.ts"; +import { SnakeCaseProps } from "../util.ts"; + +export interface Application { + /** The id of the app */ + id: string; + /** The name of the app */ + name: string; + /** The icon hash of the app */ + icon: string | null; + /** The description of the app */ + description: string; + /** An array of rpc origin urls, if rpc is enabled */ + rpcOrigins?: string[]; + /** When false only app owner can join the app's bot to guilds */ + botPublic: boolean; + /** When true the app's bot will only join upon completion of the full oauth2 code grant flow */ + botRequireCodeGrant: boolean; + /** Partial user object containing info on the owner of the application */ + owner: Partial; + /** If this application is a game sold on Discord, this field will be the summary field for the store page of its primary sku */ + summary: string; + /** The base64 encoded key for the GameSDK's GetTicket */ + verifyKey: string; + /** If the application belongs to a team, this will be a list of the members of that team */ + team: Team | null; + /** If this application is a game sold on Discord, this field will be the guild to which it has been linked */ + guildId?: string; + /** If this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists */ + primarySkuId?: string; + /** If this application is a game sold on Discord, this field will be the URL slug that links to the store page */ + slug?: string; + /** If this application is a game sold on Discord, this field will be the hash of the image on store embeds */ + coverImage?: string; + /** The application's public flags */ + flags: number; +} + +/** https://discord.com/developers/docs/topics/oauth2#application-object */ +export type DiscordApplication = SnakeCaseProps; diff --git a/src/types/oauth2/bot_auth_query.ts b/src/types/oauth2/bot_auth_query.ts new file mode 100644 index 000000000..ea1191c9c --- /dev/null +++ b/src/types/oauth2/bot_auth_query.ts @@ -0,0 +1,20 @@ +import { SnakeCaseProps } from "../util.ts"; +import { DiscordOAuth2Scopes } from "./scopes.ts"; + +export interface BotAuthenticationFlowQuery { + /** App's client id */ + clientId: string; + /** Needs to include bot for the bot flow */ + scope: DiscordOAuth2Scopes[]; + /** The permissions you're requesting */ + permissions: string; + /** Pre-fills the dropdown picker with a guild for the user */ + guildId: string; + /** True or false—disallows the user from changing the guild dropdown */ + disableGuildSelect: boolean; +} + +/** https://discord.com/developers/docs/topics/oauth2#bot-authorization-flow-bot-auth-parameters */ +export type DiscordBotAuthenticationFlowQuery = SnakeCaseProps< + BotAuthenticationFlowQuery +>; diff --git a/src/types/oauth2/get_current_authorization_information.ts b/src/types/oauth2/get_current_authorization_information.ts new file mode 100644 index 000000000..82a9bbe11 --- /dev/null +++ b/src/types/oauth2/get_current_authorization_information.ts @@ -0,0 +1,20 @@ +import { User } from "../users/user.ts"; +import { SnakeCaseProps } from "../util.ts"; +import { Application } from "./application.ts"; +import { DiscordOAuth2Scopes } from "./scopes.ts"; + +export interface GetCurrentAuthorizationInformation { + /** The current application */ + application: Partial; + /** The scopes the user has authorized the application for */ + scopes: DiscordOAuth2Scopes[]; + /** When the access token expires */ + expires: string; + /** The user who has authorized, if the user has authorized with the `identify` scope */ + user?: User; +} + +/** https://discord.com/developers/docs/topics/oauth2#get-current-authorization-information-response-structure */ +export type DiscordGetCurrentAuthoriationInformation = SnakeCaseProps< + GetCurrentAuthorizationInformation +>; diff --git a/src/types/oauth2/scopes.ts b/src/types/oauth2/scopes.ts new file mode 100644 index 000000000..732deeac6 --- /dev/null +++ b/src/types/oauth2/scopes.ts @@ -0,0 +1,23 @@ +/** https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes */ +export type DiscordOAuth2Scopes = + | "bot" + | "connections" + | "email" + | "identify" + | "guilds" + | "guilds.join" + | "gdm.join" + | "messages.read" + | "rpc" + | "rpc.api" + | "rpc.notifications" + | "webhook.incomming" + | "applications.builds.upload" + | "applications.builds.read" + | "applications.store.update" + | "applications.entitlements" + | "relationships.read" + | "activities.read" + | "activities.write" + | "applications.commands" + | "applications.commands.update";