forked from mit-oidc-client/mit-oidc-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthSession.ts
73 lines (60 loc) · 2.44 KB
/
authSession.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import axios from "axios";
import { AUTH_CONFIG } from "./authConfig";
const fs = require('fs');
const crypto = require('crypto');
/**
* Defines expected JSON input to /create_session API endpoint
*/
interface sessionIdRequest {
"email_addr": string, //Email of user
"token": string // API token to authorize action
}
/**
* Defines results from calling /create_session API endpoint
*/
interface sessionIdResponse {
"session_id": string // User's session ID (specific to email, unique across login instances)
}
/**
* Defines results from calling getSessionId()
*/
interface getSessionIdResponse {
success: boolean, //Whether or not we were able to get user's info
error_msg: string, //If failed, provide error message. Else, empty string.
session_id: string, //If success, provide user email. Else, empty string.
}
async function getSessionId(email: string): Promise<getSessionIdResponse> {
const results: getSessionIdResponse = { //Initialize our return type
success: true,
error_msg: "",
session_id: ""
};
results.session_id = crypto.randomUUID();
return Promise.resolve(results);
}
// async function getSessionId(email: string): Promise<getSessionIdResponse> {
// const results: getSessionIdResponse = { //Initialize our return type
// success: true,
// error_msg: "",
// session_id: ""
// };
// const requestJSON: sessionIdRequest = {
// email_addr: email,
// token: "YOUR_SHARED_SECRET_HERE" //Note: For security, the API endpoint to get a new session ID
// //should take in some kind of shared secret (could be keys or
// //a known string secret) and validate it.
// //Otherwise, anyone can just get a session to your application
// //and effectively be logged in.
// };
// let response;
// try {
// response = await axios.post<sessionIdResponse>(AUTH_CONFIG.session_id_uri, requestJSON);
// results.session_id = response.data.session_id; //Get session ID from JSON object
// } catch (error) {
// results.success = false;
// results.error_msg = "Failed to get a new Session ID for this user";
// results.session_id = "";
// }
// return results;
// }
export { getSessionId };