コード例 #1
0
 public OIDCAuthenticator(AuthenticationConfig authenticationConfig,
                          KeycloakConfig keycloakConfig,
                          ICredentialManager credentialManager,
                          IHttpServiceModule httpServiceModule,
                          ILogger logger) : base(authenticationConfig, keycloakConfig, credentialManager, httpServiceModule, logger)
 {
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:AeroGear.Mobile.Auth.Authenticator.AbstractAuthenticator"/> class.
 /// </summary>
 /// <param name="authenticationConfig">Authentication config.</param>
 /// <param name="keycloakConfig">Keycloak config.</param>
 /// <param name="credentialManager">Credential manager.</param>
 /// <param name="httpServiceModule">Http service module.</param>
 /// <param name="logger">Logger.</param>
 public AbstractAuthenticator(AuthenticationConfig authenticationConfig, KeycloakConfig keycloakConfig, ICredentialManager credentialManager, IHttpServiceModule httpServiceModule, ILogger logger)
 {
     this.authenticationConfig = NonNull(authenticationConfig, "authenticationConfig");
     this.keycloakConfig       = NonNull(keycloakConfig, "keycloakConfig");
     this.credentialManager    = NonNull(credentialManager, "credentialManager");
     this.httpService          = NonNull(httpServiceModule, "httpServiceModule");
     this.logger = NonNull(logger, "logger");
 }
コード例 #3
0
        private MobileCore(IPlatformInjector injector, Options options)
        {
            Logger = options.Logger ?? injector?.CreateLogger() ?? new NullLogger();

            if (injector != null && options.ConfigFileName != null)
            {
                try
                {
                    using (var stream = injector.GetBundledFileStream(options.ConfigFileName))
                    {
                        mobileConfiguration = MobileCoreConfiguration.Parse(stream);
                    }
                }
                catch (System.Exception e)
                {
                    throw new InitializationException($"{options.ConfigFileName} could not be loaded", e);
                }
            }
            else
            {
                if (options.ConfigJson != null)
                {
                    try
                    {
                        mobileConfiguration = MobileCoreConfiguration.Parse(options.ConfigJson);
                    }
                    catch (System.Exception e)
                    {
                        throw new InitializationException("invalid JSON configuration file", e);
                    }
                }
                else
                {
                    throw new InitializationException("Must provide either filename or JSON configuration in Init() options");
                }
            }
            if (options.HttpServiceModule == null)
            {
                HttpClientHandler httpClientHandler = new HttpClientHandler();
                httpClientHandler.AllowAutoRedirect = options.HttpAllowAutoRedirect;

                HttpClient httpClient = new HttpClient(httpClientHandler);
                httpClient.Timeout = TimeSpan.FromSeconds(DEFAULT_TIMEOUT);
                var httpServiceModule = new SystemNetHttpServiceModule(httpClient);
                var configuration     = GetFirstServiceConfigurationByType(httpServiceModule.Type);
                if (configuration == null)
                {
                    configuration = ServiceConfiguration.Builder.Build();
                }
                httpServiceModule.Configure(this, configuration);
                HttpLayer = httpServiceModule;
            }
            else
            {
                HttpLayer = options.HttpServiceModule;
            }
        }
コード例 #4
0
        private MobileCore(IPlatformInjector injector, Options options)
        {
            Contract.Requires(options != null);
            Logger = options.Logger ?? injector?.CreateLogger() ?? new NullLogger();

            if (injector != null && options.ConfigFileName != null)
            {
                var filename = $"{injector.DefaultResources}.{options.ConfigFileName}";
                try
                {
                    using (var stream = injector.ExecutingAssembly.GetManifestResourceStream(filename))
                    {
                        servicesConfig = MobileCoreJsonParser.Parse(stream);
                    }
                }
                catch (System.Exception e)
                {
                    throw new InitializationException($"{filename} could not be loaded", e);
                }
            }
            else
            {
                if (options.ConfigJson != null)
                {
                    try
                    {
                        MobileCoreJsonParser.Parse(options.ConfigJson);
                    }
                    catch (System.Exception e)
                    {
                        throw new InitializationException("invalid JSON configuration file", e);
                    }
                }
                else
                {
                    throw new InitializationException("Must provide either filename or JSON configuration in Init() options");
                }
            }

            if (options.HttpServiceModule == null)
            {
                HttpClient httpClient = new HttpClient();
                httpClient.Timeout = TimeSpan.FromSeconds(DEFAULT_TIMEOUT);
                var httpServiceModule = new SystemNetHttpServiceModule(httpClient);
                var configuration     = GetServiceConfiguration(httpServiceModule.Type);
                if (configuration == null)
                {
                    configuration = ServiceConfiguration.Builder.Build();
                }
                httpServiceModule.Configure(this, configuration);
                HttpLayer = httpServiceModule;
            }
            else
            {
                HttpLayer = options.HttpServiceModule;
            }
        }
コード例 #5
0
        public void SetUp()
        {
            authenticationConfig  = AuthenticationConfig.Builder.RedirectUri("test://example.com").Build();
            keycloakConfig        = new KeycloakConfig(kcConfig);
            credentialManagerMock = new CredentialManagerMock();
            IHttpResponse httpResponse        = (HttpResponseMock)HttpResponseMock.newResponse().withStatusCode(200);
            var           requestToBeExecuted = new HttpRequestToBeExecutedMock(Task.FromResult(httpResponse), null);
            IHttpRequest  httpRequestMock     = (HttpRequestMock)HttpRequestMock.newRequest().withGetResult(requestToBeExecuted);

            httpModuleMock      = (HttpServiceModuleMock)HttpServiceModuleMock.newMock().withNewRequest(httpRequestMock);
            authenticatorToTest = new OIDCAuthenticator(authenticationConfig, keycloakConfig, credentialManagerMock, httpModuleMock, logger);
        }
コード例 #6
0
 /// <summary>
 /// Set the specific implementation of HTTP to be used with the core.
 /// </summary>
 /// <param name="httpServiceModule">http service module</param>
 /// <returns>itself</returns>
 public OptionsBuilder HttpServiceModule(IHttpServiceModule httpServiceModule)
 {
     this.httpServiceModule = httpServiceModule;
     return(this);
 }