public void SetUp() { _communicationContext = MockRepository.GenerateStub<ICommunicationContext>(); _communicationContext.Stub(x => x.Request).Return(MockRepository.GenerateStub<IRequest>()); _authenticationScheme = MockRepository.GenerateStub<IAuthenticationScheme>(); _operation = MockRepository.GenerateStub<IOperation>(); }
internal AuthenticationResult( MsalAccessTokenCacheItem msalAccessTokenCacheItem, MsalIdTokenCacheItem msalIdTokenCacheItem, IAuthenticationScheme authenticationScheme, Guid correlationID, TokenSource tokenSource) { _authenticationScheme = authenticationScheme ?? throw new ArgumentNullException(nameof(authenticationScheme)); string homeAccountId = msalAccessTokenCacheItem?.HomeAccountId ?? msalIdTokenCacheItem?.HomeAccountId; string environment = msalAccessTokenCacheItem?.Environment ?? msalIdTokenCacheItem?.Environment; if (homeAccountId != null) { string username = null; if (msalIdTokenCacheItem != null) { username = msalIdTokenCacheItem.IsAdfs ? msalIdTokenCacheItem?.IdToken.Upn : msalIdTokenCacheItem?.IdToken?.PreferredUsername; } Account = new Account( homeAccountId, username, environment); } if (msalAccessTokenCacheItem != null) { AccessToken = authenticationScheme.FormatAccessToken(msalAccessTokenCacheItem); ExpiresOn = msalAccessTokenCacheItem.ExpiresOn; ExtendedExpiresOn = msalAccessTokenCacheItem.ExtendedExpiresOn; Scopes = msalAccessTokenCacheItem.ScopeSet; IsExtendedLifeTimeToken = msalAccessTokenCacheItem.IsExtendedLifeTimeToken; TokenType = msalAccessTokenCacheItem.TokenType; } UniqueId = msalIdTokenCacheItem?.IdToken?.GetUniqueId(); TenantId = msalIdTokenCacheItem?.IdToken?.TenantId; IdToken = msalIdTokenCacheItem?.Secret; CorrelationId = correlationID; AuthenticationResultMetadata = new AuthenticationResultMetadata(tokenSource); }
internal AuthenticationResult( MsalAccessTokenCacheItem msalAccessTokenCacheItem, MsalIdTokenCacheItem msalIdTokenCacheItem, IEnumerable <TenantProfile> tenantProfiles, IAuthenticationScheme authenticationScheme, Guid correlationID, TokenSource tokenSource, ApiEvent apiEvent) { _authenticationScheme = authenticationScheme ?? throw new ArgumentNullException(nameof(authenticationScheme)); string homeAccountId = msalAccessTokenCacheItem?.HomeAccountId ?? msalIdTokenCacheItem?.HomeAccountId; string environment = msalAccessTokenCacheItem?.Environment ?? msalIdTokenCacheItem?.Environment; ClaimsPrincipal = msalIdTokenCacheItem?.IdToken.ClaimsPrincipal; if (homeAccountId != null) { Account = new Account( homeAccountId, msalIdTokenCacheItem?.GetUsername(), environment, tenantProfiles: tenantProfiles); } if (msalAccessTokenCacheItem != null) { AccessToken = authenticationScheme.FormatAccessToken(msalAccessTokenCacheItem); ExpiresOn = msalAccessTokenCacheItem.ExpiresOn; ExtendedExpiresOn = msalAccessTokenCacheItem.ExtendedExpiresOn; Scopes = msalAccessTokenCacheItem.ScopeSet; IsExtendedLifeTimeToken = msalAccessTokenCacheItem.IsExtendedLifeTimeToken; TokenType = msalAccessTokenCacheItem.TokenType; } UniqueId = msalIdTokenCacheItem?.IdToken?.GetUniqueId(); TenantId = msalIdTokenCacheItem?.IdToken?.TenantId; IdToken = msalIdTokenCacheItem?.Secret; CorrelationId = correlationID; ApiEvent = apiEvent; AuthenticationResultMetadata = new AuthenticationResultMetadata(tokenSource); }
static IPrincipal CreatePrincipal(AuthenticationResult.Success success, IAuthenticationScheme scheme) { var identity = new GenericIdentity(success.Username, scheme.Name); return new GenericPrincipal(identity, success.Roles); }
internal /* for testing */ T WithAuthenticationScheme(IAuthenticationScheme scheme) { CommonParameters.AuthenticationScheme = scheme ?? throw new ArgumentNullException(nameof(scheme)); return((T)this); }
static IPrincipal CreatePrincipal(AuthenticationResult.Success success, IAuthenticationScheme scheme) { var identity = new GenericIdentity(success.Username, scheme.Name); return(new GenericPrincipal(identity, success.Roles)); }
public OnlineConnectPolicy(IAuthenticationScheme scheme, ConnectionProtocol protocol = ConnectionProtocol.Tcp) : this() { this.Protocol = protocol; this.AuthenticatonScheme = scheme; }
public RequiresOAuthInterceptor(ICommunicationContext context, IAuthenticationScheme scheme) { _context = context; _scheme = scheme; }
/// <summary> /// Get the options, for diagnostics, for an authentication-scheme. Claim-actions and events are removed. /// </summary> public static async Task <AuthenticationSchemeOptions> GetOptionsDiagnosticsAsync(this IAuthenticationScheme authenticationScheme, IServiceProvider serviceProvider) { if (authenticationScheme == null) { throw new ArgumentNullException(nameof(authenticationScheme)); } if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } var handlerType = authenticationScheme.HandlerType; while (handlerType != null) { if (handlerType.IsGenericType) { var optionsType = handlerType.GetGenericArguments().FirstOrDefault(genericArgument => typeof(AuthenticationSchemeOptions).IsAssignableFrom(genericArgument)); if (optionsType != null) { var optionsMonitorType = typeof(IOptionsMonitor <>).MakeGenericType(optionsType); if (serviceProvider.GetService(optionsMonitorType) is IOptionsMonitor <AuthenticationSchemeOptions> optionsMonitor) { var options = optionsMonitor.Get(authenticationScheme.Name); if (options != null) { var optionsFactoryType = typeof(IOptionsFactory <>).MakeGenericType(options.GetType()); var optionsFactory = serviceProvider.GetService(optionsFactoryType); // ReSharper disable All if (optionsFactory != null) { options = (AuthenticationSchemeOptions)optionsFactory.GetType().GetMethod("Create").Invoke(optionsFactory, new object[] { authenticationScheme.Name }); if (options != null) { options.Events = null; if (options is OAuthOptions oAuthOptions) { oAuthOptions.ClaimActions.Clear(); } else if (options is OpenIdConnectOptions openIdConnectOptions) { openIdConnectOptions.ClaimActions.Clear(); } return(await Task.FromResult(options).ConfigureAwait(false)); } } // ReSharper restore All } } } } handlerType = handlerType.BaseType; } return(null); }
public static IServiceCollection ConfigureAuthentication(this IServiceCollection services, IAuthenticationScheme scheme) { scheme.ConfigureAuthentication(services); return(services); }
public UnifiedTestClient(INUnitClient client, IAuthenticationScheme authScheme) : base(client) { this.authenticationScheme = authScheme; }