diff --git a/.github/workflows/build-site.yml b/.github/workflows/build-site.yml index 9459800..aa1b4e9 100644 --- a/.github/workflows/build-site.yml +++ b/.github/workflows/build-site.yml @@ -22,7 +22,7 @@ jobs: run: npm install - name: Build - run: npm run build-only -- --mode=demo + run: IAM_CLIENT_ID=${{ secrets.IAM_CLIENT_ID }} IAM_CLIENT_SECRET=${{ secrets.IAM_CLIENT_SECRET }} npm run build-only -- --mode=demo - name: Upload Binary artifacts uses: actions/upload-artifact@v4 diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml index 8c12bd0..41d7d70 100644 --- a/.github/workflows/docker-build-publish.yml +++ b/.github/workflows/docker-build-publish.yml @@ -60,6 +60,9 @@ jobs: context: . file: .docker/Dockerfile build-args: MODE_ENV=production + secrets: | + "IAM_CLIENT_ID=${{ secrets.IAM_CLIENT_ID }}" + "IAM_CLIENT_SECRET=${{ secrets.IAM_CLIENT_SECRET }}" pull: true push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/DRAFT_CHANGELOG.md b/DRAFT_CHANGELOG.md index 3c5fe8e..ea88d06 100644 --- a/DRAFT_CHANGELOG.md +++ b/DRAFT_CHANGELOG.md @@ -14,6 +14,8 @@ Version 1.0.1 de l'entrée cartographique de la Géoplateforme. #### ✨ [Ajout] +* Ajout d'un module de connexion à la GeoPlateforme [#361](https://github.com/IGNF/cartes.gouv.fr-entree-carto/pull/361) + * Ajout du widget d'import de données [#324](https://github.com/IGNF/cartes.gouv.fr-entree-carto/pull/324) * Ajout du widget de getFeatureInfo pour récupérer les informations attributaires des couches au clic [#354](https://github.com/IGNF/cartes.gouv.fr-entree-carto/pull/354) @@ -53,4 +55,5 @@ Version 1.0.1 de l'entrée cartographique de la Géoplateforme. * Ouverture responsive des panels des widgets sur petits écrans [#360](https://github.com/IGNF/cartes.gouv.fr-entree-carto/pull/360) #### 🔒 [Sécurité] + --- diff --git a/env/.env.development b/env/.env.development index 4262993..95a3c25 100644 --- a/env/.env.development +++ b/env/.env.development @@ -4,11 +4,12 @@ VITE_GPF_CONF_EDITO_URL="data/edito.json" VITE_GPF_BASE_URL_EXTERNAL= VITE_HTTP_MOCK_REQUEST=0 +VITE_HTTP_MOCK_REQUEST_SCENARIO=error # success|error IAM_URL="https://sso.geopf.fr" IAM_REALM="geoplateforme" -IAM_CLIENT_ID="cartes-gouv-dev" -IAM_CLIENT_SECRET="" +IAM_CLIENT_ID= +IAM_CLIENT_SECRET= # variable non lu nativement par vitejs # uniquement pour information par nodejs lors du build diff --git a/env/.env.production b/env/.env.production index 3d196fd..3d6e3a8 100644 --- a/env/.env.production +++ b/env/.env.production @@ -4,11 +4,12 @@ VITE_GPF_CONF_EDITO_URL="https://data.geopf.fr/annexes/cartes.gouv.fr-config/pub VITE_GPF_BASE_URL_EXTERNAL= VITE_HTTP_MOCK_REQUEST=0 +VITE_HTTP_MOCK_REQUEST_SCENARIO=error # success|error IAM_URL="https://sso.geopf.fr" IAM_REALM="geoplateforme" -IAM_CLIENT_ID="cartes-gouv-dev" -IAM_CLIENT_SECRET="" +IAM_CLIENT_ID= +IAM_CLIENT_SECRET= # variable non lu nativement par vitejs # uniquement pour information par nodejs lors du build diff --git a/src/main.ts b/src/main.ts index 8f16cac..8a16f8c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -77,7 +77,7 @@ const logger = createLogger({ const pinia = createPinia() // INFO -// on enregistre les informations de connexion dans la session +// on enregistre les informations de connexion dans le localStorage const store = storePlugin({ stores: ['service'], storage: localStorage, diff --git a/src/mocks/browser.js b/src/mocks/browser.js index 33540b3..0a0f98c 100644 --- a/src/mocks/browser.js +++ b/src/mocks/browser.js @@ -1,4 +1,7 @@ -import { setupWorker } from 'msw/browser' -import { handlers } from './handlers' +import { setupWorker } from 'msw/browser'; +import { handlers } from './handlers'; -export const worker = setupWorker(...handlers) \ No newline at end of file +const scenarioName = import.meta.env.VITE_HTTP_MOCK_REQUEST_SCENARIO; +const runtimeHandlers = handlers[scenarioName] || []; + +export const worker = setupWorker(...runtimeHandlers); \ No newline at end of file diff --git a/src/mocks/handlers.js b/src/mocks/handlers.js index 94fd9b8..7ffedd1 100644 --- a/src/mocks/handlers.js +++ b/src/mocks/handlers.js @@ -1,71 +1,75 @@ import { http, HttpResponse } from 'msw' // https://mswjs.io/docs/ -export const handlers = [ - /** - * obtenir le token - */ - http.post('https://sso.geopf.fr/realms/geoplateforme/protocol/openid-connect/token', async ({ request }) => { - return HttpResponse.json({ - "access_token": 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJuQTM1bFJNeWVEMnU3WGJDTk9UbTRORjE0eTNoYlBMcGw4TXQtVzR3STJnIn0.eyJleHAiOjE3MzE2MTkwMDksImlhdCI6MTczMTU3NTgwOSwianRpIjoiZWFkOTNjMTAtNTRlMi00NmJkLTkwYjQtNzg5ZDFhYWFlZDJmIiwiaXNzIjoiaHR0cHM6Ly9zc28uZ2VvcGYuZnIvcmVhbG1zL2dlb3BsYXRlZm9ybWUiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiMzE3MGViOGYtMWIzNS00ZWZhLWEwZjktY2E0Mjk0OTMzNGY0IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiY2FydGVzLWdvdXYtZGV2IiwiYWNyIjoiMSIsInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJkZWZhdWx0LXJvbGVzLWdlb3BsYXRlZm9ybWUiLCJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwiZGVsZXRlLWFjY291bnQiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6InByb2ZpbGUgZW1haWwiLCJjbGllbnRJZCI6ImNhcnRlcy1nb3V2LWRldiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJjbGllbnRIb3N0IjoiODIuMTQyLjIzLjQzIiwicHJlZmVycmVkX3VzZXJuYW1lIjoic2VydmljZS1hY2NvdW50LWNhcnRlcy1nb3V2LWRldiIsImdpdmVuX25hbWUiOiIiLCJjbGllbnRBZGRyZXNzIjoiODIuMTQyLjIzLjQzIiwiZmFtaWx5X25hbWUiOiIiLCJlbWFpbCI6InNlcnZpY2UtYWNjb3VudC1jYXJ0ZXMtZ291di1kZXZAbm8tcmVwbHkuZnIifQ.bVsPFTWz0dY2YmEVjUyJY3wcXXUNF4vR48Z03s4pps8zQg-93dR8c_xjfrSVvLKwW8M-ynZAoAzgrjJydlaoA26wgZlfkxJu8zVKwfnQk_TFeYg-liXiv8YoES8JPL5vRPo-Yaz4JSy-vojJfdFTGx9Sw9UI2ZEfPEgxwuUL3OBuCTqVPG4N_imElCbAFYG6y1fgoGmO8FxGpamfOk16ev9-G8hy1J1heVSzeLWzQtQRuL0bMYWFmLaa0cjrvm8Hemp7Rwe5EHQ9McyQ2_Buu6IsWEYRoaqhqHUrn5MyIKnuAJZ3cZmp8bb_Gu0wFPjzrzh0J8rSy3D60ySai7RS2g', - "expires_in": 43200, - "refresh_expires_in": 0, - "token_type": 'Bearer', - "not-before-policy": 0, - "scope": 'profile email' + +/** + * les scenarios : error ou success + * le type de scenario est configuré dans le fichier d'environnement + */ +export const handlers = { + success : [ + /** + * obtenir le token + */ + http.post('https://sso.geopf.fr/realms/geoplateforme/protocol/openid-connect/token', async ({ request }) => { + return HttpResponse.json({ + "access_token": 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiiSldUIiwia2lkIiA6ICJuQTM1bFJNeWVEMnU3WGJDTk9UbTRORjE0eTNoYlBMcGw4TXQtVzR3STJnIn0.eyJleHAiOjE3MzE2MTkwMDksImlhdCI6MTczMTU3NTgwOSwianRpIjoiZWFkOTNjMTAtNTRlMi00NmJkLTkwYjQtNzg5ZDFhYWFlZDJmIiwiaXNzIjoiaHR0cHM6Ly9zc28uZ2VvcGY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bMYWFmLaa0cjrvm8Hemp7Rwe5EHQ9McyQ2_Buu6IsWEYRoaqhqHUrn5MyIKnuAJZ3cZmp8bb_Gu0wFPjzrzh0J8rSy3D60ySai7RS2g', + "expires_in": 43200, + "refresh_expires_in": 0, + "token_type": 'Bearer', + "not-before-policy": 0, + "scope": 'profile email' + }) + }), + /** + * obtenir les informations de l'utilisateur + */ + http.get('https://data.geopf.fr/api/users/me', async ({ request }) => { + return HttpResponse.json({ + "email": "antoine.dupont@ign.fr", + "creation": "2024-01-10T11:21:28.618783Z", + "last_call": "2024-11-05T13:43:56.168033Z", + "communities_member": [ + { + "rights": [ + "UPLOAD", + "ANNEX", + "BROADCAST", + "PROCESSING" + ], + "community": { + "name": "Découverte", + "technical_name": "sandbox", + "datastore": "122b878c-aad7-4507-87b2-465e664467d3", + "supervisor": "e175d6c4-a03e-4ade-a769-86e8dd2bed58", + "public": false, + "_id": "78068951-cebc-4aec-869e-81677d211d0e" + } + } + ], + "documents_quota": 500000000, + "documents_use": 8610, + "keys_quota": 10, + "keys_use": 0, + "technical": false, + "administrator": false, + "_id": "09e091dc-51d5-4c04-963d-3045df5ce477", + "last_name": "dupont", + "first_name": "antoine" + }) }) - }), - /** - * obtenir les informations de l'utilisateur - */ - http.get('https://data.geopf.fr/api/users/me', async ({ request }) => { - return HttpResponse.json({ - "email": "jean-philippe.bazonnais@ign.fr", - "creation": "2024-01-10T11:21:28.618783Z", - "last_call": "2024-11-05T13:43:56.168033Z", - "communities_member": [ - { - "rights": [ - "UPLOAD", - "ANNEX", - "BROADCAST", - "PROCESSING" - ], - "community": { - "name": "Découverte", - "technical_name": "sandbox", - "datastore": "122b878c-aad8-4507-87b2-465e664467d3", - "supervisor": "e175d6c4-a03d-4ade-a769-86e8dd2bed58", - "public": false, - "_id": "78068951-cebc-4aec-869c-81677d211d0e" - } - }, - { - "rights": [ - "UPLOAD", - "PROCESSING", - "COMMUNITY", - "BROADCAST", - "ANNEX" - ], - "community": { - "name": "cartes.gouv.fr-config", - "technical_name": "cartes.gouv.fr-config", - "datastore": "5cb4fdb0-6f6c-4422-893d-e04564bfcc10", - "supervisor": "09e091dc-51d5-4c04-9637-3045df5ce477", - "public": false, - "_id": "f7d7279b-043f-413f-a3a3-317f1c6b5b07" - } - } - ], - "documents_quota": 500000000, - "documents_use": 8610, - "keys_quota": 10, - "keys_use": 0, - "technical": false, - "administrator": false, - "_id": "09e091dc-51d5-4c04-9637-3045df5ce477", - "last_name": "bazonnais", - "first_name": "jean-philippe" + ], + error : [ + /** + * echec sur l'obtention du token + */ + http.post('https://sso.geopf.fr/realms/geoplateforme/protocol/openid-connect/token', async ({ request }) => { + return new HttpResponse(null, { status: 404 }) + }), + /** + * echec sur l'obtention des informations de l'utilisateur + */ + http.get('https://data.geopf.fr/api/users/me', async ({ request }) => { + return new HttpResponse(null, { status: 401 }) }) - }) -] \ No newline at end of file + ] +} \ No newline at end of file diff --git a/src/views/Main.vue b/src/views/Main.vue index 874d0a7..bcd8e5c 100644 --- a/src/views/Main.vue +++ b/src/views/Main.vue @@ -93,18 +93,22 @@ service.isAccessValided() }); }) .catch((e:any) => { - throw new Error("[getUserMe]" + e.message); + console.error(e); + serviceMessageError.value = 'Error to get user info : ' + e.message; + serviceMessageClosed.value = false; }) } }) .catch((e:any) => { - throw new Error("[getAccessToken]" + e.message); + console.error(e); + serviceMessageError.value = 'Error to get token : ' + e.message; + serviceMessageClosed.value = false; }) } }) .catch((e:any) => { console.error(e); - serviceMessageError.value = e.message; + serviceMessageError.value = 'Error during authentication : ' + e.message; serviceMessageClosed.value = false; });