-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathauthentication.ts
More file actions
39 lines (35 loc) · 1.26 KB
/
authentication.ts
File metadata and controls
39 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {
IModify,
IPersistence,
IRead,
} from "@rocket.chat/apps-engine/definition/accessors";
import { IRoom } from "@rocket.chat/apps-engine/definition/rooms";
import { IUser } from "@rocket.chat/apps-engine/definition/users";
import { GithubApp } from "../GithubApp";
import { IButton, createSectionBlock } from "../lib/blocks";
import { sendNotification } from "../lib/message";
import { storeInteractionRoomData } from "../persistance/roomInteraction";
export async function authorize(
app: GithubApp,
read: IRead,
modify: IModify,
user: IUser,
room: IRoom,
persistence: IPersistence
): Promise<void> {
const message = `Login to GitHub`;
const block = await getGithubOauthBlock(app, user, modify, message);
await storeInteractionRoomData(persistence,user.id,room.id);
await sendNotification(read, modify, user, room, message, block);
}
export async function getGithubOauthBlock(app: GithubApp, user: IUser, modify: IModify, message: string) {
const url = await app
.getOauth2ClientInstance()
.getUserAuthorizationUrl(user);
const button: IButton = {
text: "GitHub Login",
url: url.toString(),
};
const block = await createSectionBlock(modify, message, button);
return block;
}