Hybrid Flow Sample and Test
January 16, 2024 ยท View on GitHub
Version: 1.2.7
This client uses the OIDC Hybrid Flow to obtain an access token. See the main ADH Authentication samples page README for more information about this flow.
Requirements
- .NET 6.0 or later
- Note: Visual Studio 17.1 or later is required for development against .NET 6.0
- Web Browser with Javascript enabled
- You will need Google Chrome if you want to run the automated test
- The sample is configured using the file appsettings.placeholder.json. Before editing, rename this file to
appsettings.json. This repository's.gitignorerules should prevent the file from ever being checked in to any fork or branch, to ensure credentials are not compromised. - Replace the placeholders in the
appsettings.jsonfile with your Tenant Id, Client Id and Client Secret - Ensure that this client was created to allow Refresh Tokens
- If this client does not allow refresh tokens, no refresh token will be issued upon authentication
- Ensure that the client contains $"{RedirectHost}:{RedirectPort}/{RedirectPath}" in the list of RedirectUris
- Default value from config is:
https://127.0.0.1:54567/signin-oidc - You can change the values to match your preferences
- Default value from config is:
Running the sample
Prerequisites
-
Register a Hybrid client in ADH and ensure that the registered client in ADH contains
https://127.0.0.1:54567/signin-oidcin the list of RedirectUris. -
Replace the placeholders in the
appsettings.jsonfile with your Tenant Id, Client Id, and Client Secret obtained from registration.
Using Visual Studio
- Load the .csproj in this directory
- Rebuild project
- Run it
- If you want to see the token and other outputs from the program, put a breakpoint at the end of the main method and run in debug mode
- Follow the prompts in the web browser to log in
- Keep in mind that if you are already logged in with the same Account in the browser, you will not have to log in again
- Return to the application after having been authenticated in the browser
Using Command Line
- Make sure you have the install location of dotnet added to your path
- Run the following command from the location of this project:
dotnet run
- Follow the prompts in the web browser to log in
- Return to the application after having been authenticated in the browser
Running the automated test
Test Prerequisites
- Make sure Google Chrome is the default browser on your test system.
- Download the ChromeDriver version from
http://chromedriver.storage.googleapis.com/index.htmlcorresponding to the version of Google Chrome that is installed. Set the environmental variable ChromeWebDriver to the directory containing the Chrome Driver executable. - Update the
appsettings.jsonwith the username and password for the Microsoft account that will be used to log in. The test is only written to work with a personal Microsoft account and must only prompt for only username followed by password (no Two-Factor authentication or other consent or informational prompts). Also if the location of the sample application has been modified then change the RedirectHost and/or RedirectPort.
Test Using Visual Studio
- Load the .csproj from the HybridFlowTest directory above this in Visual Studio
- Rebuild project
- Open Test Explorer and make sure there is one test called Test1 showing
- Run the test
Test Using Command Line
- Make sure you have the install location of dotnet added to your path
- Run the following command from the location of the HybridFlowTest project (you may need to run as Administrator for the test to use the Chrome Driver):
dotnet test
Tested against DotNet 6.0
For the main ADH Authentication samples page ReadMe
For the main ADH samples page ReadMe
For the main AVEVA samples page ReadMe