Compare commits

..

No commits in common. "7d102772d95356bde3db4e5b48b125e460e098f7" and "7d47eec1f2a610164d31d5ac4aeec226928bd1fa" have entirely different histories.

2 changed files with 26 additions and 12 deletions

13
src/config/idnot.ts Normal file
View File

@ -0,0 +1,13 @@
export const idnotConfig = {
IDNOT_API_KEY: process.env.IDNOT_API_KEY,
IDNOT_ANNUARY_BASE_URL: process.env.IDNOT_ANNUARY_BASE_URL,
// OAuth2 credentials (these should ideally be moved to env vars for security)
CLIENT_ID: 'B3CE56353EDB15A9',
CLIENT_SECRET: '3F733549E879878344B6C949B366BB5CDBB2DB5B7F7AB7EBBEBB0F0DD0776D1C',
REDIRECT_URI: 'http://local.lecoffreio.4nkweb:3000/authorized-client',
// API URLs
TOKEN_URL: 'https://qual-connexion.idnot.fr/user/IdPOAuth2/token/idnot_idp_v1',
API_BASE_URL: 'https://qual-api.notaires.fr/annuaire'
};

View File

@ -1,18 +1,19 @@
import fetch from 'node-fetch';
import { idnotConfig } from '../../config/idnot';
import { IdNotUser, ECivility, EOfficeStatus, EIdnotRole } from '../../types';
export class IdNotService {
static async exchangeCodeForTokens(code: string) {
const params = {
client_id: process.env.IDNOT_CLIENT_ID,
client_secret: process.env.IDNOT_CLIENT_SECRET,
redirect_uri: process.env.IDNOT_REDIRECT_URI,
client_id: idnotConfig.CLIENT_ID,
client_secret: idnotConfig.CLIENT_SECRET,
redirect_uri: idnotConfig.REDIRECT_URI,
grant_type: 'authorization_code',
code: code
};
const tokens = await (
await fetch(process.env.IDNOT_TOKEN_URL, {
await fetch(idnotConfig.TOKEN_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
@ -26,11 +27,11 @@ export class IdNotService {
static async getUserRattachements(idNot: string) {
const searchParams = new URLSearchParams({
key: process.env.IDNOT_API_KEY || '',
key: idnotConfig.IDNOT_API_KEY || '',
deleted: 'false'
});
const url = `${process.env.IDNOT_ANNUARY_BASE_URL}/api/pp/v2/personnes/${idNot}/rattachements?` + searchParams;
const url = `${idnotConfig.IDNOT_ANNUARY_BASE_URL}/api/pp/v2/personnes/${idNot}/rattachements?` + searchParams;
const json = await (
await fetch(url, {
@ -43,11 +44,11 @@ export class IdNotService {
static async getOfficeRattachements(idNot: string) {
const searchParams = new URLSearchParams({
key: process.env.IDNOT_API_KEY || '',
key: idnotConfig.IDNOT_API_KEY || '',
deleted: 'false'
});
const url = `${process.env.IDNOT_ANNUARY_BASE_URL}/api/pp/v2/entites/${idNot}/personnes?` + searchParams;
const url = `${idnotConfig.IDNOT_ANNUARY_BASE_URL}/api/pp/v2/entites/${idNot}/personnes?` + searchParams;
const json = await (
await fetch(url, {
@ -60,11 +61,11 @@ export class IdNotService {
static async getUserData(profileIdn: string) {
const searchParams = new URLSearchParams({
key: process.env.IDNOT_API_KEY || ''
key: idnotConfig.IDNOT_API_KEY || ''
});
const userData = await (
await fetch(`${process.env.API_BASE_URL}/api/pp/v2/rattachements/${profileIdn}?` + searchParams, {
await fetch(`${idnotConfig.API_BASE_URL}/api/pp/v2/rattachements/${profileIdn}?` + searchParams, {
method: 'GET'
})
).json();
@ -74,11 +75,11 @@ export class IdNotService {
static async getOfficeLocationData(locationsUrl: string) {
const searchParams = new URLSearchParams({
key: process.env.IDNOT_API_KEY || ''
key: idnotConfig.IDNOT_API_KEY || ''
});
const officeLocationData = await (
await fetch(`${process.env.API_BASE_URL}${locationsUrl}?` + searchParams, {
await fetch(`${idnotConfig.API_BASE_URL}${locationsUrl}?` + searchParams, {
method: 'GET'
})
).json();