Can authenticate using OpenID
This commit is contained in:
@ -1,8 +1,45 @@
|
||||
import { atom } from "jotai";
|
||||
import { APIClient } from "./ApiClient";
|
||||
|
||||
const TokenStateKey = "auth-token";
|
||||
|
||||
export class AuthApi {
|
||||
/**
|
||||
* Check out whether user is signed in or not
|
||||
*/
|
||||
static get SignedIn(): boolean {
|
||||
return false;
|
||||
return sessionStorage.getItem(TokenStateKey) !== null;
|
||||
}
|
||||
|
||||
static authStatus = atom(this.SignedIn);
|
||||
|
||||
/**
|
||||
* Start OpenID login
|
||||
*
|
||||
* @param id The ID of the OIDC provider to use
|
||||
*/
|
||||
static async StartOpenIDLogin(id: string): Promise<{ url: string }> {
|
||||
return (
|
||||
await APIClient.exec({
|
||||
uri: "/auth/start_openid_login",
|
||||
method: "POST",
|
||||
jsonData: { provider: id },
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish OpenID login
|
||||
*/
|
||||
static async FinishOpenIDLogin(code: string, state: string): Promise<void> {
|
||||
const res: { user_id: number; token: string } = (
|
||||
await APIClient.exec({
|
||||
uri: "/auth/finish_openid_login",
|
||||
method: "POST",
|
||||
jsonData: { code: code, state: state },
|
||||
})
|
||||
).data;
|
||||
|
||||
sessionStorage.setItem(TokenStateKey, res.token);
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ export class ServerApi {
|
||||
/**
|
||||
* Get cached configuration
|
||||
*/
|
||||
static Config(): ServerConfig {
|
||||
static get Config(): ServerConfig {
|
||||
if (config === null) throw new Error("Missing configuration!");
|
||||
return config;
|
||||
}
|
||||
|
Reference in New Issue
Block a user