@s21toolkit/auth
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

s21auth 📦🤰

Библиотека авторизации/аутентификации для платформы edu.21-school.ru.

npm install @s21toolkit/auth

Использование

Получение токена:

import { fetchAccessToken } from "@s21toolkit/auth"

const response = await fetchAccessToken("username", "p4ssw0rd")

console.log(response.accessToken)

Получение контекстных заголовков (нужны для большей части запросов):

import { fetchContextHeaders } from "@s21toolkit/auth"

const headers = await fetchContextHeaders(accessToken)

Автоматическое обновление токена:

import { UserAuthProvider, S21_GQL_API_URL, getAuthHeaders } from "@s21toolkit/auth"

const auth = new UserAuthProvider("username", "p4ssw0rd")

const response = await fetch(S21_GQL_API_URL, {
   method: "POST",
   headers: {
      ...await getAuthHeaders(auth)
   },
   body: JSON.stringify({ query: "..." })
})

Readme

Keywords

none

Package Sidebar

Install

npm i @s21toolkit/auth

Weekly Downloads

49

Version

1.1.0

License

MIT

Unpacked Size

17.9 kB

Total Files

5

Last publish

Collaborators

  • bgenia