26 lines
826 B
TypeScript
26 lines
826 B
TypeScript
import { axios } from "@/api/index";
|
|
import { query, route } from "@/routing";
|
|
|
|
const LOGIN_ENDPOINT = "/access/login";
|
|
const DEV_LOGIN_ENDPOINT = "/dev/login";
|
|
|
|
const CLIENT_ID = process.env.LOGIN_CLIENT_ID || "PraktykiClientId";
|
|
const AUTHORIZE_URL = process.env.AUTHORIZE || "https://logowanie.pg.edu.pl/oauth2.0/authorize";
|
|
|
|
export async function login(code?: string): Promise<string> {
|
|
const response = code
|
|
? await axios.get<string>(LOGIN_ENDPOINT, { params: { code }})
|
|
: await axios.get<string>(DEV_LOGIN_ENDPOINT);
|
|
|
|
return response.data;
|
|
}
|
|
|
|
export function getAuthorizeUrl() {
|
|
return query(AUTHORIZE_URL, {
|
|
response_type: "code",
|
|
scope: "user_details",
|
|
client_id: CLIENT_ID,
|
|
redirect_uri: window.location.origin + route("user_login") + "/check/pg",
|
|
})
|
|
}
|