Azure Active Directory Authentication Sample for DotVVM
Sign in to the Azure Portal and open (or create) your Azure Active Directory resource.
Open the Overview tab and copy the Directory ID value. Paste it in the
TenantIdapplication setting in the
web.configfile in OWIN or
appsettings.jsonin ASP.NET Core.
Open the App registrations tab and open (or create) the app registration.
Copy the Application ID value and paste it in the
ClientIdapplication setting in the
Make sure that the URL on which the web app is running, is listed in the Home Page field or in the Reply URLs section. The URL must match including the HTTP/HTTPS and port.
In ASP.NET Core version, set the
PostLogoutRedirectUriapplication setting to the application root URL.
Now the application should work with all accounts from the directory.
Note: If you decide to use
code response type instead of default
id_token, generate and set
ClientSecret in the configuration file as well. The secret can be generated in App registrations page in the Authentication section.
If you want to make the application multi-tenant (to allow the users to sign in even if they are from a different Azure Active Directory tenant), you need to make these changes:
In the Properties tab of the App Registration, switch the Multi-tenanted field to Yes.
appsettings.json, change the
TenantIdto the value
How to run the sample
Open the GitHub repo in Visual Studio or
git clone https://github.com/riganti/dotvvm-samples-dotvvm-samples-azuread-auth.git
AspNetCore/DotvvmAuthSample/DotvvmAuthSample.sln(ASP.NET Core) or
Owin/DotvvmAuthSample/DotvvmAuthSample.sln(.NET Framework with OWIN)
DotvvmAuthSampleproject and select View > View in Browser
What you can learn in the sample
- How to configure Azure Active Directory authentication in a DotVVM application (see Authentication page in the DotVVM Docs to find more info)