Skip to content

School 21 / SberClass auth library for JS environments

License

Notifications You must be signed in to change notification settings

s21toolkit/s21auth

 
 

Repository files navigation

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: "..." })
})

About

School 21 / SberClass auth library for JS environments

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%