How to setup OKTA for Sitecore Integration - MVP Site

*****************************************************************
18/Nov/2023 Update:

The MVP site is now part of XMCloud repo. The local setup instructions in the XMCloud repo readme page is fairly explanatory except that when the sites opens up as part of .\up.ps1, the local mvp site alone will look like this:

404 page not found

If you scroll down the XMCloud read me page, you will find this section:


Based on the above instruction, I opened a separate PowerShell window, navigated to the rendering folder as stated and executed dotnet restore followed-by dotnet run commands to encounter this error:

Unhandled exception. System.ArgumentException: Your Okta URL must start with https. Current value: <<Add Okta domain>>. You can copy your domain from the Okta Developer Console. Follow these instructions to find it: https://bit.ly/finding-okta-domain (Parameter 'OktaDomain')
   at Okta.AspNet.Abstractions.OktaWebOptionsValidator`1.Validate(OktaWebOptions options)
   at Okta.AspNetCore.OktaAuthenticationOptionsExtensions.AddOktaMvc(AuthenticationBuilder builder, OktaMvcOptions options)
   at Mvp.Feature.User.Extensions.StartUpExtensions.AddFeatureUser(IServiceCollection services, IConfiguration configuration) in C:\projects\fork\XM-Cloud-Introduction\src\Feature\User\rendering\Extensions\StartUpExtensions.cs:line 20
   at Mvp.Project.MvpSite.Rendering.Startup.ConfigureServices(IServiceCollection services) in C:\projects\fork\XM-Cloud-Introduction\src\Project\MvpSite\rendering\Startup.cs:line 61
   at Program.<Main>$(String[] args) in C:\projects\fork\XM-Cloud-Introduction\src\Project\MvpSite\rendering\Program.cs:line 8

After logging into my OKTA domain url (I continue with Github account after login menu click) and setting up application integration (explained down below as part of my original old post), I added the OKTA domain and other details in my .env file as below, I was still getting the same error as above:


This is when I realised that I needed to add the same details in appsettings.Development.json under C:\projects\fork\XM-Cloud-Introduction\src\Project\MvpSite\rendering


After doing the same, dotnet run provided me the desired result of seeing the mvp site in https://localhost:5001/:


Now, from the next time you up.ps1, the https://mvp.xmcloudcm.localhost/ address also should work fine.

Debugging with Docker:

Note that debugging MVP project becomes active when https://mvp.xmcloudcm.localhost/ is available else, you would not be able to see the dotnet.exe process (depicted here below). Also, you actually don't need the client instance (https://localhost:5001) running  if you have to debug the Docker instance. Also note that I didn't touch the Visual Studio build or publish for Docker debugging!


Note: If you don't see dotnet.exe in the process list even after refreshing, it means there is a problem with the code although build might be successful. So, revert/rectify code and deploy to see the process.

Also, ensure x64 is configured in case of 64-bit processor else, values will not be displayed on hover while debugging: 



On the other hand, in case if you wish to visualise code changes faster in the browser, use the client application or in other words, use the dotnet run command on the rendering folder to view in the http://localhost:5000 browser window.

Error:

[+] Building 0.0s (0/0)
[+] Building 0.0s (0/0)
da08cdacdbae: Downloading [======>                                            ]   16.2MB/117MB
[+] Building 0.0s (0/0)
time="2023-11-19T09:30:30+11:00" level=error msg="Can't add file \\\\?\\C:\\projects\\fork\\XM-Cloud-Introduction\\src\\.vs\\XmCloudIntroduction\\FileContentIndex\\13608797-40ee-4f22-9321-6b14ba08d085.vsidx to tar: open \\\\?\\C:\\projects\\fork\\XM-Cloud-Introduction\\src\\.vs\\XmCloudIntroduction\\FileContentIndex\\13608797-40ee-4f22-9321-6b14ba08d085.vsidx: The process cannot access the file because it is being used by another process."
time="2023-11-19T09:30:30+11:00" level=error msg="Can't add file \\\\?\\C:\\projects\\fork\\XM-Cloud-Introduction\\src\\.vs\\XmCloudIntroduction\\FileContentIndex\\441a1500-4846-4104-80de-b1acd46eedfa.vsidx to tar: archive/tar: missed writing 741216 bytes"
time="2023-11-19T09:30:30+11:00" level=error msg="Can't add file \\\\?\\C:\\projects\\fork\\XM-Cloud-Introduction\\src\\.vs\\XmCloudIntroduction\\config to tar: archive/tar: missed writing 741216 bytes"
Error response from daemon: unexpected EOF



Solution:

Usually happens if sln is open in Visual Studio. Either close Visual Studio and retry or restart computer and retry up.ps1

Additional tip:

if you want to debug the Visual Studio application code but get the above error, close Visual Studio, execute up.ps1, once the application is up and running, open Visual Studio and then attach the break-point. 

**************************************************************
Original Post:

Recently, while trying to setup the Sitecore MVP Site running on Sitecore 10.2, I had to setup OKTA application for the integration. This blog article covers the same.

Use the Custom OKTA trial option:

Note that the email address must be a business email address and gmail address will not work! Signup and get an email with activate link. 

On clicking the activation link, will have to reset password and login to the custom domain created for you:



Create an application integration in OKTA:

Step-1:

Select OIDC as signin method and web application as application type:



Step-2:

Ensure to check client credentials in the next page:


Final Confirmation Page:





Once you do the necessary steps to setup the client id, client secret and domain as listed above, you can sign-in using the new domain name from here - https://login.okta.com/ by providing the custom domain provided in the automated email.

Then, you can find the active application here - https://<okta custom domain>/admin/apps/active
and you will find the application integration in the list.


Ensure that the OKTA domain in the .env file is prefixed with https:// else, you get the following error on compose up:


Unhandled exception. System.ArgumentException: Your Okta URL must start with https. Current value: dev-8977037.okta.com. You can copy your domain from the Okta Developer Console. Follow these instructions to find it: https://bit.ly/finding-okta-domain (Parameter 'OktaDomain')

   at Okta.AspNet.Abstractions.OktaWebOptionsValidator`1.Validate(OktaWebOptions options)

   at Okta.AspNetCore.OktaAuthenticationOptionsExtensions.AddOktaMvc(AuthenticationBuilder builder, OktaMvcOptions options)

   at Mvp.Foundation.User.Extensions.StartUpExtensions.AddFoundationUser(IServiceCollection services, IConfiguration configuration) in C:\solution\src\Foundation\User\rendering\Extensions\StartUpExtensions.cs:line 19

   at Mvp.Project.MvpSite.Rendering.Startup.ConfigureServices(IServiceCollection services) in C:\solution\src\Project\MvpSite\rendering\Startup.cs:line 71

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)

   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)

   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)

   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)

   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)

   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)

   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()

   at Microsoft.Extensions.Hosting.HostBuilder.Build()

   at Mvp.Project.MvpSite.Rendering.Program.Main(String[] args) in C:\solution\src\Project\MvpSite\rendering\Program.cs:line 16

watch : Refresh server running at ws://localhost:49173.

watch : Started 'C:\Program Files\dotnet\dotnet.exe' '' with process id 2348

watch : Running dotnet with the following arguments: run --no-launch-profile

watch : Started

Comments

Popular Posts