public IHttpActionResult Get(string token) { if (string.IsNullOrWhiteSpace(token)) { return(BadRequest()); } var storageProviderName = ConfigurationManager.AppSettings["ITokenStorageProviderName"]; ITokenStorageProvider storage = StorageProviderFactory.Create(storageProviderName); if (storage == null) { return(InternalServerError(new ArgumentException("Storage provider not found."))); } //try to get the item var value = storage.Read(token); if (string.IsNullOrWhiteSpace(value)) { return(NotFound()); } return(Ok(value)); }
private ITokenStorageProvider GetStorageProvider() { //get the storage provider, based on config setting //Note: more robust implementation would probably use Dependency Injection, for now using a factory var storageProviderName = ConfigurationManager.AppSettings["ITokenStorageProviderName"]; ITokenStorageProvider storage = StorageProviderFactory.Create(storageProviderName); return(storage); }
/// <summary> /// Creates a new <see cref="IPublicClientApplication"/> /// </summary> /// <param name="clientId">Client ID (also known as <i>Application ID</i>) of the application as registered in the application registration portal (https://aka.ms/msal-net-register-app).</param> /// <param name="tokenStorageProvider">A <see cref="ITokenStorageProvider"/> for storing and retrieving access token.</param> /// <param name="tenant">Tenant to sign-in users. This defaults to <c>organizations</c> if non is specified.</param> /// <param name="nationalCloud">A <see cref="NationalCloud"/> which identifies the national cloud endpoint to use as the authority. This defaults to the global cloud <see cref="NationalCloud.Global"/> (https://login.microsoftonline.com).</param> /// <returns>A <see cref="IPublicClientApplication"/></returns> public static IPublicClientApplication CreateClientApplication(string clientId, ITokenStorageProvider tokenStorageProvider = null, string tenant = null, NationalCloud nationalCloud = NationalCloud.Global) { TokenCacheProvider tokenCacheProvider = new TokenCacheProvider(tokenStorageProvider); string authority = NationalCloudHelpers.GetAuthority(nationalCloud, tenant ?? AuthConstants.Tenants.Organizations); return(new PublicClientApplication(clientId, authority, tokenCacheProvider.GetTokenCacheInstnce())); }
/// <summary> /// Creates a new <see cref="IConfidentialClientApplication"/> /// </summary> /// <param name="clientId">Client ID (also known as <i>Application ID</i>) of the application as registered in the application registration portal (https://aka.ms/msal-net-register-app)</param> /// <param name="clientCredential">A <see cref="Microsoft.Identity.Client.ClientCredential"/> created either from an application secret or a certificate</param> /// <param name="tokenStorageProvider">A <see cref="ITokenStorageProvider"/> for storing and retrieving access token. </param> /// <param name="tenant">Tenant to sign-in users. This defaults to <c>common</c> if non is specified</param> /// <param name="nationalCloud">A <see cref="NationalCloud"/> which identifies the national cloud endpoint to use as the authority. This defaults to the global cloud <see cref="NationalCloud.Global"/> (https://login.microsoftonline.com) </param> /// <returns>A <see cref="IConfidentialClientApplication"/></returns> public static IConfidentialClientApplication CreateClientApplication(string clientId, ClientCredential clientCredential, ITokenStorageProvider tokenStorageProvider = null, string tenant = null, NationalCloud nationalCloud = NationalCloud.Global) { TokenCacheProvider tokenCacheProvider = new TokenCacheProvider(tokenStorageProvider); string authority = NationalCloudHelpers.GetAuthority(nationalCloud, tenant ?? AuthConstants.Tenants.Common); return(new ConfidentialClientApplication(clientId, authority, string.Empty, clientCredential, null, tokenCacheProvider.GetTokenCacheInstnce())); }
public static ITokenStorageProvider Create(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException(nameof(name)); } ITokenStorageProvider provider = null; try { ObjectHandle handle = Activator.CreateInstance("Example.Library.TokenStorage", name); provider = (ITokenStorageProvider)handle.Unwrap(); } catch (Exception) { //TODO: should provide some logging, maybe Log4Net or another library, out of scope for this assignment } return(provider); }
internal TokenCacheProvider(ITokenStorageProvider tokenStorageProvider = null) { _tokenStorageProvider = tokenStorageProvider; }