microsoftgraph / msgraph-sdk-dotnet-auth

Archived - use the TokenCredential classes provided by Azure.Identity. https://docs.microsoft.com/en-us/dotnet/api/overview/azure/identity-readme
https://graph.microsoft.com
MIT License
78 stars 19 forks source link

MSAL Auth Providers #16

Closed peombwa closed 5 years ago

peombwa commented 5 years ago

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.

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