1
0
Fork 0
mirror of https://github.com/betagouv/mon-entreprise synced 2025-02-09 06:25:12 +00:00
mon-entreprise/server/source/oauth.ts
Benjamin Arias a51920b44c
Support Usager : Implémentation de la messagerie Crisp (#2329)
* feat: Ajoute l'iframe crisp ainsi que le bloc custom html

* wip

* feat: Renomme le dossier standup.. + ajoute la fonction crisp

* fix: Install not broken version + add update meta

* feat: Ajoute le formulaire

* fix: Corrige htmlFor et id

* feat: Ajoute la logique pour récupérer nombre de réponses et les issues

* fix: uncomment stuff

* fix: Retire log

* chore: Renomme fonction

* chore: Renomme fonction

* chore: Renomme fonction

* feat: Retire commentaires

* fix: Refacto urlParams

* chore : Nettoyage de reliquats

* fix : Ajoute TextAreaField et utilise TextField

* fix: Style issues

* fix: Améliore types

* feat: Cleaning

* feat: Ajoute variable d'env website id

* feat: Met à jour README

* wip placeholder url

* feat: Ajoute une fonction de validation du body

* feat: Ajoute validation

* chore: update yarn.lock

* fix: Add missing secret ref + cleaning
2022-10-24 15:03:14 +02:00

67 lines
1.3 KiB
TypeScript

import got from 'got'
export interface OAuthResponse {
access_token: string
token_type: string
expires_in: number
scope: string
refresh_token: string
id_token: string
}
interface OAuthParams {
serverUrl: string
clientSecret: string
clientId: string
redirectUri: string
}
interface GetOAuthParams extends OAuthParams {
code: string
}
export const getAccessToken = ({
serverUrl,
clientSecret,
clientId,
redirectUri,
code,
}: GetOAuthParams) =>
got.post<OAuthResponse>(`${serverUrl}/oauth/access_token`, {
form: {
client_secret: clientSecret,
client_id: clientId,
redirect_uri: redirectUri,
grant_type: 'authorization_code',
code,
},
responseType: 'json',
throwHttpErrors: true,
})
interface RefreshOAuthParams extends OAuthParams {
serverUrl: string
clientSecret: string
clientId: string
redirectUri: string
refreshToken: string
}
export const refreshAccessToken = ({
serverUrl,
clientSecret,
clientId,
redirectUri,
refreshToken,
}: RefreshOAuthParams) =>
got.post<OAuthResponse>(`${serverUrl}/oauth/access_token`, {
form: {
client_secret: clientSecret,
client_id: clientId,
redirect_uri: redirectUri,
grant_type: 'refresh_token',
refresh_token: refreshToken,
},
responseType: 'json',
throwHttpErrors: true,
})