From 8893ef72baa99a38fb3fc17d9b26211902a4ee8e Mon Sep 17 00:00:00 2001 From: Will McRae Date: Thu, 19 Dec 2024 12:31:04 -0600 Subject: [PATCH] Remove iTwin Auth (#4) * update READMEs * en: remove itwin auth requirement * update readme --- common/src/itwin/cesiumCuratedContent.ts | 12 ++++++------ r3f-sample/.env.example | 1 - r3f-sample/README.md | 3 +-- r3f-sample/src/globe.jsx | 4 ++-- r3f-sample/src/main.jsx | 19 ++----------------- .../BentleyCesiumCuratedContentPlugin.js | 2 +- threejs-sample/.env.example | 1 - threejs-sample/README.md | 3 +-- threejs-sample/src/main.ts | 11 +---------- 9 files changed, 14 insertions(+), 42 deletions(-) diff --git a/common/src/itwin/cesiumCuratedContent.ts b/common/src/itwin/cesiumCuratedContent.ts index 7e45768..4f4b086 100644 --- a/common/src/itwin/cesiumCuratedContent.ts +++ b/common/src/itwin/cesiumCuratedContent.ts @@ -3,14 +3,14 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -export async function getCuratedCesiumContent(iTwinId: string, imsPrefix: string, accessToken: string) { +export async function getCuratedCesiumContent(imsPrefix: string, accessToken: string) { const headers = { "Authorization": accessToken, "Accept": "application/vnd.bentley.itwin-platform.v1+json", "Content-Type": "application/json" }; - let url = `https://${imsPrefix}api.bentley.com/curated-content/cesium/?iTwinId=${iTwinId}`; + let url = `https://${imsPrefix}api.bentley.com/curated-content/cesium/`; const response = await fetch(url, { headers }); const responseJson = await response.json(); @@ -18,14 +18,14 @@ export async function getCuratedCesiumContent(iTwinId: string, imsPrefix: string return responseJson; } -export async function getCesiumCuratedContentTiles(contentId: string, iTwinId: string, imsPrefix: string, accessToken: string) { +export async function getCesiumCuratedContentTiles(contentId: string, imsPrefix: string, accessToken: string) { const headers = { "Authorization": accessToken, "Accept": "application/vnd.bentley.itwin-platform.v1+json", "Content-Type": "application/json" }; - let url = `https://${imsPrefix}api.bentley.com/curated-content/cesium/${contentId}/tiles?iTwinId=${iTwinId}`; + let url = `https://${imsPrefix}api.bentley.com/curated-content/cesium/${contentId}/tiles`; const response = await fetch(url, { headers }); const responseJson = await response.json(); @@ -33,14 +33,14 @@ export async function getCesiumCuratedContentTiles(contentId: string, iTwinId: s return { url: responseJson.url, accessToken: responseJson.accessToken, attributions: responseJson.attributions }; } -export async function getCesiumMoonTerrianTiles(iTwinId: string, imsPrefix: string, accessToken: string) { +export async function getCesiumMoonTerrianTiles(imsPrefix: string, accessToken: string) { const headers = { "Authorization": accessToken, "Accept": "application/vnd.bentley.itwin-platform.v1+json", "Content-Type": "application/json" }; - let url = `https://${imsPrefix}api.bentley.com/curated-content/cesium/2684829/tiles?iTwinId=${iTwinId}`; + let url = `https://${imsPrefix}api.bentley.com/curated-content/cesium/2684829/tiles`; const response = await fetch(url, { headers }); const responseJson = await response.json(); diff --git a/r3f-sample/.env.example b/r3f-sample/.env.example index b9d383f..3f2ebc3 100644 --- a/r3f-sample/.env.example +++ b/r3f-sample/.env.example @@ -1,3 +1,2 @@ VITE_CLIENT_ID="**YOUR CLIENT ID**" VITE_IMS_PREFIX ="" -VITE_ITWIN_ID="**OPTIONAL ITWIN ID**" \ No newline at end of file diff --git a/r3f-sample/README.md b/r3f-sample/README.md index b00f573..e150227 100644 --- a/r3f-sample/README.md +++ b/r3f-sample/README.md @@ -10,9 +10,8 @@ In a .env file in the `r3f-sample` directory: - `VITE_CLIENT_ID` - SPA Application Client ID needed to sign in with Bentley IMS (required) - `VITE_IMS_PREFIX` - Bentley IMS authority prefix (optional) -- `VITE_ITWIN_ID` - iTwin Id of an iTwin. You will need to have permission to read this iTwin (optional, if no Id is provided the user's primary account iTwin will be used) -For an example of the `.env` file, an one has been provided [here](./.env.example) +For an example of the `.env` file, one has been provided [here](./.env.example) ## Authentication diff --git a/r3f-sample/src/globe.jsx b/r3f-sample/src/globe.jsx index 227181b..e3d20a3 100644 --- a/r3f-sample/src/globe.jsx +++ b/r3f-sample/src/globe.jsx @@ -14,7 +14,7 @@ import { BentleyCesiumCuratedContentPlugin } from './plugins/BentleyCesiumCurate import { Canvas } from '@react-three/fiber'; import { Environment } from '@react-three/drei'; -export function Globe ({ accessToken, itwinId, imsPrefix }) { +export function Globe ({ accessToken, imsPrefix }) { return ( - + diff --git a/r3f-sample/src/main.jsx b/r3f-sample/src/main.jsx index d486b6f..11dc6c7 100644 --- a/r3f-sample/src/main.jsx +++ b/r3f-sample/src/main.jsx @@ -8,14 +8,12 @@ import { createRoot } from 'react-dom/client'; import { Globe } from './globe'; import { getBentleyAuthClient } from "common"; -import { ITwinsAccessClient } from "@itwin/itwins-client"; const imsPrefix = import.meta.env.VITE_IMS_PREFIX ?? ""; const clientId = import.meta.env.VITE_CLIENT_ID; function App() { const [accessToken, setAccessToken] = useState(''); - const [itwinId, setItwinId] = useState(import.meta.env.VITE_ITWIN_ID); useEffect( () => { const fetchAccessToken = async () => { @@ -28,24 +26,11 @@ function App() { fetchAccessToken(); }, [] ); - useEffect( () => { - const fetchiTwinId = async () => { - if(accessToken && !itwinId) { - const iTwinsAccessClient = new ITwinsAccessClient(`https://${imsPrefix}api.bentley.com/itwins`); - const iTwinsResponse = await iTwinsAccessClient.getPrimaryAccountAsync(accessToken); - - setItwinId(iTwinsResponse.data?.id); - } - } - - fetchiTwinId(); - }, [accessToken] ); - - if (!accessToken || !itwinId) { + if (!accessToken) { return
Loggin' in...
; } - return ; + return ; } createRoot( document.getElementById( 'root' ) ).render( diff --git a/r3f-sample/src/plugins/BentleyCesiumCuratedContentPlugin.js b/r3f-sample/src/plugins/BentleyCesiumCuratedContentPlugin.js index 366754c..9876215 100644 --- a/r3f-sample/src/plugins/BentleyCesiumCuratedContentPlugin.js +++ b/r3f-sample/src/plugins/BentleyCesiumCuratedContentPlugin.js @@ -20,7 +20,7 @@ export class BentleyCesiumCuratedContentPlugin { } init(tiles) { - tiles.rootURL = `https://${this.imsPrefix}api.bentley.com/curated-content/cesium/96188/tiles?iTwinId=${this.itwinId}`; + tiles.rootURL = `https://${this.imsPrefix}api.bentley.com/curated-content/cesium/96188/tiles`; this.tiles = tiles; this.endpointURL = tiles.rootURL; diff --git a/threejs-sample/.env.example b/threejs-sample/.env.example index b9d383f..3f2ebc3 100644 --- a/threejs-sample/.env.example +++ b/threejs-sample/.env.example @@ -1,3 +1,2 @@ VITE_CLIENT_ID="**YOUR CLIENT ID**" VITE_IMS_PREFIX ="" -VITE_ITWIN_ID="**OPTIONAL ITWIN ID**" \ No newline at end of file diff --git a/threejs-sample/README.md b/threejs-sample/README.md index d5edc9f..ab3cef2 100644 --- a/threejs-sample/README.md +++ b/threejs-sample/README.md @@ -10,9 +10,8 @@ In a .env file in the `threejs-sample` directory: - `VITE_CLIENT_ID` - SPA Application Client ID needed to sign in with Bentley IMS (required) - `VITE_IMS_PREFIX` - Bentley IMS authority prefix (optional) -- `VITE_ITWIN_ID` - iTwin Id of an iTwin. You will need to have permission to read this iTwin (optional, if no Id is provided the user's primary account iTwin will be used) -For an example of the `.env` file, an one has been provided [here](./.env.example) +For an example of the `.env` file, one has been provided [here](./.env.example) ## Authentication diff --git a/threejs-sample/src/main.ts b/threejs-sample/src/main.ts index 6620195..7aedc50 100644 --- a/threejs-sample/src/main.ts +++ b/threejs-sample/src/main.ts @@ -8,7 +8,6 @@ import * as THREE from "three"; import { getBentleyAuthClient, getCesiumMoonTerrianTiles } from "common"; import { GUI } from "lil-gui"; import { TilesRenderer, LUNAR_ELLIPSOID, GlobeControls } from "3d-tiles-renderer"; -import { ITwinsAccessClient, ITwin, ITwinsAPIResponse} from "@itwin/itwins-client"; const imsPrefix = import.meta.env.VITE_IMS_PREFIX ?? ""; const clientId = import.meta.env.VITE_CLIENT_ID; @@ -20,15 +19,7 @@ if (!clientId) { const authClient = await getBentleyAuthClient(clientId, imsPrefix); const accessToken = await authClient.getAccessToken(); -let iTwinId = import.meta.env.VITE_ITWIN_ID; -if (!iTwinId) { - const iTwinsAccessClient: ITwinsAccessClient = new ITwinsAccessClient(`https://${imsPrefix}api.bentley.com/itwins`); - const iTwinsResponse: ITwinsAPIResponse = await iTwinsAccessClient.getPrimaryAccountAsync(accessToken); - - iTwinId = iTwinsResponse.data?.id; -} - -const cesiumMoonTerrianTiles = await getCesiumMoonTerrianTiles(iTwinId, imsPrefix, accessToken); +const cesiumMoonTerrianTiles = await getCesiumMoonTerrianTiles(imsPrefix, accessToken); var camera = {} as THREE.PerspectiveCamera; var controls = {} as GlobeControls;