A set of MSAL authentication providers that implement IAuthenticationProvider and are used by GraphServiceClient to authenticate http request messages.
MsalAuthenticationProviderOption which implements lAuthenticationProviderOption and is used to set provider specific provider options.
BaseRequest extensions methods to set MsalAuthenticationProviderOption.
ITokenStorageProvider interface that's used to create token cache storage provider.
ToGraphUserAccount extension method which converts a ClaimsPrincipal to a GraphUserAccount.
Usage
Confidential Client Authentication Providers
A set of auth providers which uses MSAL's confidential client applications.
AuthorizationCodeProvider
Uses MSAL's acquire token by authorization code to authenticate HttpRequestMessages.
ConfidentialClientApplication cca = AuthorizationCodeProvider.CreateClientApplication(clientId, redirectUri, clientCredential);
AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(cca, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
ClientCredentialProvider
ConfidentialClientApplication cca = ClientCredentialProvider.CreateClientApplication(clientId, redirectUri, clientCredential);
ClientCredentialProvider authProvider = new ClientCredentialProvider(cca);
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
OnBehalfOfProvider
ConfidentialClientApplication cca = OnBehalfOfProvider.CreateClientApplication(clientId, redirectUri, clientCredential);
OnBehalfOfProvider authProvider = new OnBehalfOfProvider(cca, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
Public Client Authentication Providers
A set of auth providers which uses MSAL's public client applications.
DeviceCodeProvider
PublicClientApplication pca = DeviceCodeProvider.CreateClientApplication(clientId);
DeviceCodeProvider authProvider = new DeviceCodeProvider(pca, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
IntegratedWindowsAuthenticationProvider
PublicClientApplication pca = IntegratedWindowsAuthenticationProvider.CreateClientApplication(clientId);
IntegratedWindowsAuthenticationProvider authProvider = new IntegratedWindowsAuthenticationProvider(pca, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
InteractiveAuthenticationProvider
PublicClientApplication pca = InteractiveAuthenticationProvider.CreateClientApplication(clientId);
InteractiveAuthenticationProvider authProvider = new InteractiveAuthenticationProvider(pca, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
UsernamePasswordProvider
PublicClientApplication pca = UsernamePasswordProvider.CreateClientApplication(clientId);
UsernamePasswordProvider authProvider = new UsernamePasswordProvider(pca, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
Creating A National Cloud Aware Auth Provider
ConfidentialClientApplication cca = AuthorizationCodeProvider.CreateClientApplication(clientId, redirectUri, clientCredential, null, tenantName, NationalCloud.China);
AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(cca, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
Creating Auth Provider With An External Token Cache Provider
ITokenStorageProvider tokenStorageProvider = new RedisCacheProvider();
ConfidentialClientApplication cca = AuthorizationCodeProvider.CreateClientApplication(clientId, redirectUri, clientCredential, tokenStorageProvider);
AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(cca, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
Setting Request Authentication Provider Options
WithScopes
var me = await graphClient.Me.Request().WithScopes(scopes).GetAsync();
WithForceRefresh
var me = await graphClient.Me.Request().WithForceRefresh(true).GetAsync();
WithUserAccount
var me = await graphClient.Me.Request().WithUserAccount(graphUserAccount).GetAsync();
WithUserAssertion
var me = await graphClient.Me.Request().WithUserAssertion(userAssertion).GetAsync();
WithUsernamePassword
var me = await graphClient.Me.Request().WithUsernamePassword(username, password).GetAsync();
Adds
Usage
Confidential Client Authentication Providers
A set of auth providers which uses MSAL's confidential client applications.
AuthorizationCodeProvider
Uses MSAL's acquire token by authorization code to authenticate HttpRequestMessages.
ClientCredentialProvider
OnBehalfOfProvider
Public Client Authentication Providers
A set of auth providers which uses MSAL's public client applications.
DeviceCodeProvider
IntegratedWindowsAuthenticationProvider
InteractiveAuthenticationProvider
UsernamePasswordProvider
Creating A National Cloud Aware Auth Provider
Creating Auth Provider With An External Token Cache Provider
Setting Request Authentication Provider Options