Giter VIP home page Giter VIP logo

ms-identity-ciam-dotnet-tutorial's Introduction

page_type languages products description urlFragment
sample
csharp
microsoft-identity-web
msalnet
Tutorial: Enable your .NET application to sign-in users and call APIs with Azure AD for Customers
ms-identity-ciam-dotnet-tutorial

Tutorial: Enable your .NET application to sign-in users and call APIs with Azure AD for Customers

This tutorial aims to take you through the fundamentals of modern authentication with Azure AD Consumer Identity and Access Management (CIAM), using the Microsoft Authentication Library for .NET and Microsoft.Identity.Web.

Prerequisites

Please refer to each sample's README for sample-specific prerequisites.

Recommendations

  • jwt.ms for inspecting your tokens
  • Fiddler for monitoring your network activity and troubleshooting
  • Follow the Azure AD Blog to stay up-to-date with the latest developments

Please refer to each sample's README for sample-specific recommendations.

Contents

Chapter 1: Sign-in a user to your application

Sign-in using an ASP.NET Core web app
Sign-in your users with Azure AD for Customers and learn to work with ID Tokens. Learn how single sign-on (SSO) works. Learn to integrate with user-flows and external identity providers.
Sign-in using a MAUI cross-platform app
Sign-in your users with Azure AD for Customers and learn to work with ID Tokens. Learn how single sign-on (SSO) works. Learn to integrate with user-flows and external identity providers.
Sign-in using a browserless app
Sign-in your users with Azure AD for Customers and learn to work with a browserless device code flow. Learn to integrate with user-flows and external identity providers.
Sign-in using WPF app
Sign-in your users with Azure AD for Customers and learn to work with ID Tokens using desktop applications. Learn to integrate with user-flows and external identity providers.

Chapter 2: Protect an API and call the API from your client app

Use an ASP.NET Core web application and call a protected web API on Azure AD for Customers
Protect your web API with the Azure AD for Customers. Use a client application to sign-in a user, acquire an Access Token for your web API and call your protected web API.*
Use a Blazor Server application and call a protected web API on Azure AD for Customers
Protect your web API with the Azure AD for Customers. Use a client application to sign-in a user, acquire an Access Token for your web API and call your protected web API.*
Use a daemon application to send and receive data from a protected web API on Azure AD for Customers
Protect your web API with the Azure AD for Customers. Use a daemon application to acquire an Access Token for your web API and call your protected web API.

We'd love your feedback

Were we successful in addressing your learning objective? Consider taking a moment to share your experience with us.

More information

Learn more about the Microsoft identity platform:

See more code samples:

Community Help and Support

Use Stack Overflow to get support from the community. Ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before. Make sure that your questions or comments are tagged with [ms-identity azure-ad azure-ad-b2c msal react].

If you find a bug in the sample, please raise the issue on GitHub Issues.

To provide a recommendation, visit the following User Voice page.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.opensource.microsoft.com.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

ms-identity-ciam-dotnet-tutorial's People

Contributors

bgavrilms avatar cilwerner avatar dependabot[bot] avatar derisen avatar dickson-mwendia avatar ellymakuba avatar emakuba avatar henrymbuguakiarie avatar jennyf19 avatar jmprieur avatar kellyyangsong avatar kengaderdus avatar microsoft-github-operations[bot] avatar microsoftopensource avatar mpminayo avatar mtrilbybassett avatar mwanzias avatar owenrichards1 avatar ptittof57 avatar salman90 avatar trwalke avatar v-michaelmi avatar westin-m avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ms-identity-ciam-dotnet-tutorial's Issues

Action required: migrate or opt-out of migration to GitHub inside Microsoft

Migrate non-Open Source or non-External Collaboration repositories to GitHub inside Microsoft

In order to protect and secure Microsoft, private or internal repositories in GitHub for Open Source, which are not related to open source projects or requiring collaboration with 3rd parties (customer, partners, etc.) must be migrated to GitHub inside Microsoft a.k.a GitHub Enterprise Cloud with Enterprise Managed User (GHEC EMU).

Action

✍️ Please RSVP to opt-in or opt-out of the migration to GitHub inside Microsoft.

❗Only users with admin permission in the repository are allowed to respond. Failure to provide a response will result to your repository getting automatically archived.🔒

Instructions

Reply with a comment on this issue containing one of the following optin or optout command options below.

✅ Opt-in to migrate

@gimsvc optin --date <target_migration_date in mm-dd-yyyy format>

Example: @gimsvc optin --date 03-15-2023

OR

❌ Opt-out of migration

@gimsvc optout --reason <staging|collaboration|delete|other>

Example: @gimsvc optout --reason staging

Options:

  • staging : My project will ship as Open Source
  • collaboration : Used for external or 3rd party collaboration with customers, partners, suppliers, etc.
  • delete : This repository will be deleted because it is no longer needed.
  • other : Other reasons not specified

Need more help? 🖐️

Add Readme for Blazor Sample

Missing Readme for blazor-wasm sample.

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Build errors in Severity (MSB4018) The "GenerateStaticWebAsssetsPropsFile" task failed unexpectedly.

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Screenshot (85)

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Versions

Screenshot (82)

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Is it possible to use Managed Identity instead of Entra App & Secret for configuring the authentication in Blazor App?

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [X ] feature request
- [X ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Want to remove the dependency of App Secret in the authentication flow.

Any log messages given by the failure

Expected/desired behavior

Ability to configure using Managed Identity

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

[iOS] Crash with MAUI Net 9 Preview

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ X ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Run the MAUI Sample with .NET 9 Preview on MacOs and Select iOS Simulator iPhone 15 Pro

Expected/desired behavior

ClaimsView.xaml displayed with info

OS and Version?

macOS Sonoma (with VS Code)

Versions

Nugets versions in csproj

  <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0-preview.4.24224.3" />
  <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0-preview.4.24224.3" />
  <PackageReference Include="Microsoft.Identity.Client" Version="4.60.3" />
  <PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.60.3" />
  <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

Mention any other details that might be useful

I don't know if it's a maui issue or azure identity issue but the application crash on this code:
(MSALClientHelper.cs)

      return await this.PublicClientApplication.AcquireTokenInteractive(scopes)
                                  .WithParentActivityOrWindow(PlatformConfig.Instance.ParentWindow)
                                  .ExecuteAsync()
                                  .ConfigureAwait(false);

Thanks! We'll be in touch soon.

DeviceCode sample does not work using Entra External ID tenant

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x ] bug report -> please search issues before submitting
- [ ] feature request
- [x ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Create a Entra External ID tenant and follow the remaining instructions. The arcticle here provides details on the steps and issues.

Any log messages given by the failure

The URL provided in devicecode.VerificationUrl is "https://microsoft.com/devicelogin" but when logging in with a local account the follow error is displayed "AADSTS500208: The domain is not a valid login domain for the account type". The article here documents the issue.

Expected/desired behavior

The correct URL for the domain should be provided e.g. "https://tenant_sub_domain.ciamlogin.com/common/oauth2/deviceauth". I'm not sure if this is a documentation issue or Microsoft.Identity.Client / MSAL issue.

OS and Version?

Windows 11

Versions

.NET 8 console app using Microsoft.Identity.Client version 4.59.0

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Getting the following error after I login to my Azure B2C account in IOS

This issue is for:

- [X] bug report -> please search issues before submitting
- [ ] feature request
- [X] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

I used the sample provided from git clone https://github.com/Azure-Samples/ms-identity-ciam-dotnet-tutorial.git
I followed the instructions and setup everything as requested.
I am able to login successfully but the SignInUserAndAcquireAccessToken method throws an exception on the last line:
return this.AuthResult.AccessToken; because AuthResult is null. See log message below for issue with Entitlements.plist

I am using automatic provisioning to may apple developer account. I have KeyChain checked in the Entitlements.plist file. The contents of my Entitlements.plist file is what came with the sample which has:

`

keychain-access-groups $(AppIdentifierPrefix)com.microsoft.adalcache `

I added the override of the OpenUrl method in my AppDelegate.cs file, which does not get called. Not sure if that matters? I also don't understand why the instructions say to ensure this is used but yet it is not in the sample code.

Give the error below I have done extensive research and I don't see what I have done wrong.

I have also looked at this url given in the error message which appears to be an older version of what you have in the sample above:
https://aka.ms/msal-net-enable-keychain-groups

Any assistance would be greatly appreciated.

Any log messages given by the failure

NOTE: I replaced my actual APP ID Prefix with MYAPPREFIX below. The actual error has the correct APP ID Prefix
ErrorCode: missing_entitlements
Microsoft.Identity.Client.MsalClientException: The application does not have keychain access groups enabled in the Entitlements.plist. As a result, there was a failure to save to the iOS keychain. The keychain access group 'MYAPPREFIX.com.microsoft.msalcache' is not enabled in the Entitlements.plist. Also, use the WithIosKeychainSecurityGroup api to set the keychain access group. See https://aka.ms/msal-net-enable-keychain-groups for more details on enabling keychain access groups and entitlements.

Expected/desired behavior

To get a valid AuthToken and have the info displayed on the page as specified in the tutorial.

OS and Version?

Windows 11, Visual Studio 17.10.0, .net 7.0, mac OS Ventura13.6.3

Daemon sample does not work with CIAM URL. Works fine with https://login.microsoftonline.com

Daemon sample does not work with CIAM URL.

When trying to run the following error occurs:

Unhandled exception. MSAL.NetCore.4.53.0.0.MsalClientException: 
        ErrorCode: tenant_override_non_aad
Microsoft.Identity.Client.MsalClientException: WithTenantId can only be used when an AAD authority is specified at the application level.
   at Microsoft.Identity.Client.AbstractAcquireTokenParameterBuilder`1.WithTenantId(String tenantId)
   at Microsoft.Identity.Web.TokenAcquisition.GetAuthenticationResultForAppAsync(String scope, String authenticationScheme, String tenant, TokenAcquisitionOptions tokenAcquisitionOptions)
   at Microsoft.Identity.Web.DefaultAuthorizationHeaderProvider.CreateAuthorizationHeaderForAppAsync(String scopes, AuthorizationHeaderProviderOptions downstreamApiOptions, CancellationToken cancellationToken)
   at Microsoft.Identity.Web.DownstreamApi.CallApiInternalAsync(String serviceName, DownstreamApiOptions effectiveOptions, Boolean appToken, HttpContent content, ClaimsPrincipal user, CancellationToken cancellationToken)
   at Microsoft.Identity.Web.DownstreamApi.PostForAppAsync[TInput,TOutput](String serviceName, TInput input, Action`1 downstreamApiOptionsOverride, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in C:\GitHub\AzureSamples\ms-identity-ciam-dotnet-tutorial\2-Authorization\3-call-own-api-dotnet-core-daemon\ToDoListClient\Program.cs:line 30
   at Program.<Main>(String[] args)

You can find the error description here

Seems to be thrown by the core library with a tenant override which is not registered to be allowed.

Relevant code here

Why does the sign-in-maui MSALClientHelper.cs have a reference to Microsoft.Identity.Client.Desktop?

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [x ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Follow the instructions from Tutorial: Create a .NET MAUI shell app

Any log messages given by the failure

After referencing the Microsoft.Identity.Client.Desktop package needed in MSALClientHelper.cs the MAUI app will not build and shows a NETSDK1136: The target framework must be Windows error.

Expected/desired behavior

After following the tutorial as written, the code builds.

OS and Version?

Windows 10

Versions

Mention any other details that might be useful

I created a git repo that just follows the instructions from the tutorial. The commits should tell the story (https://github.com/scottpantall/sign-in-maui/commits/master/).

The only reason for the Microsoft.Identity.Client.Desktop package in MSALClientHelper.cs is to use the WithWindowsEmbeddedBrowserSupport() extension method which documentation says is unnecessary for MAUI applications. When I removed this reference I was able to build my MAUI application.

TokenAcquirerFactory.GetDefaultInstance() By default reads an appsettings.json, why not azure app config

  • bug report -> please search issues before submitting
  • [x ] feature request
  • documentation issue or request
  • regression (a behavior that used to work and stopped in a new release)
            // Get the Token acquirer factory instance. By default it reads an appsettings.json
            // file if it exists in the same folder as the app (make sure that the 
            // "Copy to Output Directory" property of the appsettings.json file is "Copy if newer").
            var tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance();

is it possible to somehow add functionality to get the value from your own azure app configuration the same way like below example so I dont need to store client secret inside the app, by default GetDefaultInstance(); gets that from appsettings.json that is not safe for the production
```
tokenAcquirerFactory.Services.AddDownstreamApi(ServiceName,
config.GetSection("DownstreamApi"));


Chapter 2: Use an ASP.NET Core web application and call a protected web API on Azure AD for Customers

Trying to execute 2-Authorization - 1-call-own-api-aspnet-core-mvc in External ID tenant.

My service api, client app registration and appsettings are correct. But getting the below error -

Response content: '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.
fail: Microsoft.IdentityModel.LoggingExtensions.IdentityLoggerAdapter[0]
IDX20807: Unable to retrieve document from: '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'. HttpResponseMessage: '[PII of type 'System.Net.Http.HttpResponseMessage' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]', HttpResponseMessage.Content: '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.
fail: Microsoft.IdentityModel.LoggingExtensions.IdentityLoggerAdapter[0]
Message: IDX20803: Unable to obtain configuration from: 'https://trialexternalidfordemobban.ciamlogin.com/10e93a61-a289-4484-9a82-799587f1f2a9/.well-known/openid-configuration'. Will retry at '10/2/2023 7:35:20 PM +00:00'. Exception: 'System.IO.IOException: IDX20807: Unable to retrieve document from: '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'. HttpResponseMessage: '[PII of type 'System.Net.Http.HttpResponseMessage' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]', HttpResponseMessage.Content: '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)'., InnerException: System.IO.IOException.
fail: Microsoft.IdentityModel.LoggingExtensions.IdentityLoggerAdapter[0]
Message: IDX40001: Issuer: 'https://sts.windows.net/10e93a61-a289-4484-9a82-799587f1f2a9/', does not match any of the valid issuers provided for this application. , InnerException: System.InvalidOperationException.

This issue is for a: (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Windows 11

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

404 link to: [Tutorial: Create user flow in Azure Active Directory CIAM]

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [x ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Link can be found in the README.md @ [Tutorial: Create user flow in ....]:
https://github.com/Azure-Samples/ms-identity-ciam-dotnet-tutorial/blob/main/2-Authorization/2-call-own-api-blazor-server/README.md

Expected/desired behavior

Working Link

Mention any other details that might be useful

Broken Link:
https://github.com/microsoft/entra-previews/blob/PP2/docs/3-Create-sign-up-and-sign-in-user-flow.md


Thanks! We'll be in touch soon.

Failed to find the placed holder mentioned iOS AppDelegate.cs file

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [X ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Refer to https://github.com/Azure-Samples/ms-identity-ciam-dotnet-tutorial/tree/main/1-Authentication/2-sign-in-maui#:~:text=Open%20the%20Platforms%5CiOS,from%20the%20Azure%20portal.
A reference is made to the placeholder in the iOS AppDelegate.cs file. I do not see that placeholder.

Any log messages given by the failure

Expected/desired behavior

Adjust the AppDelegate.cs file to include the placeholder or adjust the step in the documentation.

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
iOS

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.