Livestock API Samples: WPF application signing in users with Azure Active Directory B2C and calling a livestock Information systems API
This sample is using MSAL.NET 4.x.
This simple sample demonstrates how to use the [Microsoft Authentication Library (MSAL) for .NET] to get an access token and call a Livestock Information Systems API secured by Azure AD B2C.
(1) Open the livestock-api-sample-client-wpf
project.
(2) Set as startup Project
(3) Add folloiwng required values in App.cofig files:
(a) TenantName
(b) RedirectUrl
(c) CLientId
(d) PolicySignUpSignIn
(e) PolicyResetPassword
(f) ApiScopes
(g) APiEndpoint
(h) APISubscriptionKey
and run the project.
The sample demonstrates the following functionality:
- Click the sign-in button at the top of the application screen. The sample works exactly in the same way regardless of the account type you choose, apart from some visual differences in the authentication and consent experience. Upon successful sign in, the application screen will list some basic profile info for the authenticated user and show buttons that allow you to call an API and sign out.
- Close the application and reopen it. You will see that the app retains access to the API and retrieves the user info right away, without the need to sign in again.
- Sign out by clicking the Sign out button and confirm that you lose access to the API until the exit interactive sign in.
- Call the api by clicking on the Call API buttom
For more information on Azure B2C, see the Azure AD B2C documentation homepage.