====== Example: Enable Bentley IMS Login ======
The example below has an extra ''Sign In to 3DM Cloud (Bentley IMS)'' option available.
===== Preparations =====
=== 1. SPA Client Registration ====
To get started, your application needs to be registered with the Bentley IMS to use the iTwin Platform APIs.\\
You can do so here : https://https://developer.bentley.com/register
Enter the following information :
* Name: The name of your application
* API Associations/Allowed Scopes: Leave empty for now
* Application Type: SPA
* Redirect URI: The URI of the callback document (see 2. Callback document).
{{:227:viewer:sdk:examples_js:sdk_register.png?600|}}
After creating the client, we will now manage it from a different place.\\
Navigate to [[https://imsoidcui.bentley.com]] and select "Manage Applications".
Here, edit the client you just created using the "Edit" Action :
{{:227:viewer:sdk:examples_js:sdk_client_list.png?600|}}
Update the following elements :
* Scopes : Press the "Add +" button to add the following scopes :
* orbit-3dm
* realitydata:read
* rbac-service
* CORS Origin URLs: Press the "Add +" button to add the list of domains where your application is hosted.
{{:227:viewer:sdk:examples_js:sdk_client_edit.png?600|}}
=== 2. Callback document ====
A callback document must be made available. The URL to this document will be used to hand off the authorization code to the application.
* Download https://cdn.3dmapping.cloud/22.7.0/javascript/oauth-flow-callback.html
* Edit PARENT_LOCATION to hold the list of domains where your application is hosted.
* Place this callback HTML file somewhere on a server hosted by you (preferably next to your application).
===== SDK Initialisation =====
To enable the option to login in using Bentley IMS, you need to provide these options at startup :
var options= new AMap();
options.set(Constants.STARTUP_BENTLEY_IMS_ENABLE,true);
options.set(Constants.STARTUP_BENTLEY_IMS_CLIENT_ID,"");
options.set(Constants.STARTUP_BENTLEY_IMS_REDIRECT_URL,"");
let viewer = new SDKViewer("app name",divElement,options);