Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.Configure <
                CrmConnectionSettings>(Configuration.GetSection("CrmConnection"));

            var oauthSettingsSection = Configuration.GetSection("OAuth");
            var ouathSettings        = new OAuthSettings()
            {
                ClientId     = oauthSettingsSection.GetValue <string>("ClientId"),
                ClientSecret = oauthSettingsSection.GetValue <string>("ClientSecret"),
                Authority    = oauthSettingsSection.GetValue <string>("Authority")
            };

            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(OAuthConfig.GetApiResources())
            .AddInMemoryClients(OAuthConfig.GetClient(ouathSettings));

            // Configures the ability to authenticate against the OAuth Identity Server
            services.AddAuthentication("Bearer")
            .AddJwtBearer("Bearer", options =>
            {
                options.Authority            = ouathSettings.Authority;
                options.RequireHttpsMetadata = true;
                options.Audience             = "apiAccess";
            });

            services.AddScoped <ICdsWebApi, CdsWebApi>();
            services.AddScoped <ICollateralAssetAdministrationController, CollateralAssetAdministrationControllerImplementation>();
            services.AddScoped <IConsumerLoanController, ConsumerLoanControllerImplementation>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AuthManager"/> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <exception cref="System.ArgumentNullException">
        /// RedirectUrl
        /// or
        /// DiscoveryUrl
        /// or
        /// ClientId
        /// or
        /// ClientSecret
        /// or
        /// Scope
        /// or
        /// ServiceContextBaseUrl
        /// </exception>
        public AuthManager(OAuthSettings settings)
        {
            if (string.IsNullOrEmpty(settings.RedirectUri))
            {
                throw new ArgumentNullException("RedirectUrl");
            }
            else
            {
                RedirectUri = settings.RedirectUri;
            }

            if (string.IsNullOrEmpty(settings.DiscoveryUrl))
            {
                throw new ArgumentNullException("DiscoveryUrl");
            }
            else
            {
                DiscoveryUrl = settings.DiscoveryUrl;
            }

            if (string.IsNullOrEmpty(settings.ClientId))
            {
                throw new ArgumentNullException("ClientId");
            }
            else
            {
                ClientId = settings.ClientId;
            }

            if (string.IsNullOrEmpty(settings.ClientSecret))
            {
                throw new ArgumentNullException("ClientSecret");
            }
            else
            {
                ClientSecret = settings.ClientSecret;
            }

            if (string.IsNullOrEmpty(settings.Scope))
            {
                throw new ArgumentNullException("Scope");
            }
            else
            {
                Scope = settings.Scope;
            }

            if (string.IsNullOrEmpty(settings.ServiceContextBaseUrl))
            {
                throw new ArgumentNullException("ServiceContextBaseUrl");
            }
            else
            {
                ServiceContextBaseUrl = settings.ServiceContextBaseUrl;
            }

            cred      = string.Format("{0}:{1}", ClientId, ClientSecret);
            enc       = Convert.ToBase64String(Encoding.ASCII.GetBytes(cred));
            basicAuth = string.Format("{0} {1}", "Basic", enc);
        }
Example #3
0
 public RequestMiddleware(RequestDelegate next, ILogger logger, IOptions <OAuthSettings> oAuthSettings, IOptions <IgnitionConfigurations> ignitionSettings)
 {
     _next             = next;
     _logger           = logger;
     _oAuthSettings    = oAuthSettings.Value;
     _ignitionSettings = ignitionSettings.Value;
 }
Example #4
0
        public App()
        {
            // clientId: Your OAuth2 client id (get from Instagram API management portal)
            // scope: The scopes for the particular API you're accessing. The format for this will vary by API. ("basic" is all you need for this spp)
            // authorizeUrl: The auth URL for the service (at the time of this writing, it's "https://api.instagram.com/oauth/authorize/")
            // redirectUrl: The redirect URL for the service (as you've specified in the Instagram API management portal)

            // If you'd like to know more about how to integrate with an OAuth provider,
            // I personally like the Instagram API docs: http://instagram.com/developer/authentication/

            XamarinAuthSettings =
                new OAuthSettings(
                    clientId: TravelCommunity.Resources.Client.ClientId,
                    scope: "basic",
                    authorizeUrl: "https://api.instagram.com/oauth/authorize/",
                    redirectUrl: "https://aimore.github.io/");

            // Hold on to the NavigationPage as a static, so that we can easily access it via App later.
            //_NavPage = new NavigationPage(new InstagramLogin());
            //Navigation = _NavPage.Navigation;
            MainPage = new AppStartPage();
            //var page = new ContentPage();
            //page.Content = new VideoPlayer();
            //MainPage = page;
        }
        protected override void beforeEach()
        {
            theSettings      = new OAuthSettings();
            theConfiguration = new BottleConfiguration("Test");

            Services.Inject(theSettings);
        }
Example #6
0
 public JirnalCore()
 {
     oauthSettings_  = new OAuthSettings();
     ProjectSettings = new ProjectSettings();
     jiraProxy_      = new JiraProxy(oauthSettings_.BaseUrl);
     JiraOAuthClient = new JiraOAuthClient(oauthSettings_.BaseUrl, oauthSettings_.ConsumerKey, oauthSettings_.ConsumerSecret);
     MessageBus      = new MessageBus();
 }
Example #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // For use in ReadUsingOptionsPattern page
            services.Configure <PositionOptions>(
                Configuration.GetSection(PositionOptions.Position)
                );

            // Register the settings for "OAuthSettings" section
            var settings = new OAuthSettings();

            Configuration.Bind(OAuthSettings.OAuthSection, settings);
            services.AddSingleton(settings);

            // ProjectService Registration
            services.AddScoped <IProjectService, ProjectService>();

            // ProjectRepository Registration
            services.AddScoped <IProjectRepository, ProjectRepository>();

            // Register the ApplicationDbContext
            // Create the database by following steps that use migrations to create it:
            // - dotnet tool install --global dotnet-ef
            // - dotnet add package Microsoft.EntityFrameworkCore.Design
            // - dotnet ef migrations add InitialCreate
            // - dotnet ef database update
            // This installs dotnet ef and the design package which is required to run the command on a project.
            // The migrations command scaffolds a migration to create the initial set of tables for the model.
            // The database update command creates the database and applies the new migration to it.
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("Default")));

            // The following line enables Application Insights telemetry collection.
            services.AddApplicationInsightsTelemetry();

            // Register the settings for "ApplicationInsights" section as a service for injection from DI container
            var applicationInsightsSettings = new ApplicationInsightsSettings();

            Configuration.Bind(ApplicationInsightsSettings.ApplicationInsightsSectionKey, applicationInsightsSettings);
            services.AddSingleton(applicationInsightsSettings);

            // Use telemetry initializers when you want to enrich telemetry with additional information
            services.AddSingleton <ITelemetryInitializer, CloudRoleTelemetryInitializer>();

            // Remove a specific built-in telemetry initializer
            var telemetryInitializerToRemove = services.FirstOrDefault <ServiceDescriptor>
                                                   (t => t.ImplementationType == typeof(AspNetCoreEnvironmentTelemetryInitializer));

            if (telemetryInitializerToRemove != null)
            {
                services.Remove(telemetryInitializerToRemove);
            }

            // You can add custom telemetry processors to TelemetryConfiguration by using the extension method AddApplicationInsightsTelemetryProcessor on IServiceCollection.
            // You use telemetry processors in advanced filtering scenarios
            services.AddApplicationInsightsTelemetryProcessor <StaticWebAssetsTelemetryProcessor>();

            services.AddRazorPages();
        }
 public void Initialize(string appKey, string appSecret, string callbackUrl = null)
 {
     OAuthSettings = new OAuthSettings();
     OAuthSettings.AuthorizeUrl = "https://api.weibo.com/oauth2/authorize";
     OAuthSettings.AccessTokenUrl = "https://api.weibo.com/oauth2/access_token";
     OAuthSettings.CallbackUrl = string.IsNullOrEmpty(callbackUrl) ? "https://api.weibo.com/oauth2/default.html" : callbackUrl;
     OAuthSettings.AppKey = appKey;
     OAuthSettings.AppSecret = appSecret;
 }
        public void uses_the_specified_OAuthSettings()
        {
            var theSettings = new OAuthSettings {ConsumerKey = "blah", ConsumerSecret = "private"};
            var registry = new FubuRegistry();
            registry.Import<ApplyTwitterAuthentication>(x => x.UseOAuthSettings(theSettings));

            var graph = BehaviorGraph.BuildFrom(registry);
            graph.Services.DefaultServiceFor<OAuthSettings>().Value.ShouldEqual(theSettings);
        }
Example #10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <MvcOptions>(options =>
            {
                options.Filters.Add(new RequireHttpsAttribute());
            });

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            //This is FacebookOAuth config routing.
            var facebookConfig = new OAuthSettings();

            Configuration.GetSection("FacebookOAuthSettings")
            .Bind(facebookConfig);
            services
            .AddAuthentication()
            .AddFacebook(facebookOptions =>
            {
                facebookOptions.AppId     = facebookConfig.AppId;
                facebookOptions.AppSecret = facebookConfig.AppSecret;
            });

            //This is Google OAuth config routing.
            var googleConfig = new OAuthSettings();

            Configuration.GetSection("GoogleOAuthSettings")
            .Bind(googleConfig);
            services
            .AddAuthentication()
            .AddGoogle(googleOptions =>
            {
                googleOptions.ClientId     = googleConfig.ClientId;
                googleOptions.ClientSecret = googleConfig.ClientSecret;
            });

            ////This is Charity  config routing.
            //var charityConfig = new APIsettings();
            //Configuration.GetSection("CharityAPISettings")
            //    .Bind(charityConfig);
            //services
            //    .(charityOptions =>
            //    {
            //        charityOptions.AppId = charityConfig.ClientId;
            //        charityOptions.ClientSecret = charityConfig.ClientSecret;
            //    });

            // Add application services.
            services.AddTransient <IEmailSender, EmailSender>();

            services.AddMvc();
        }
Example #11
0
        protected override void beforeEach()
        {
            theSettings = new OAuthSettings
            {
                ConsumerKey    = Guid.NewGuid().ToString(),
                ConsumerSecret = Guid.NewGuid().ToString()
            };

            Services.Inject(theSettings);
        }
Example #12
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            OAuthSettings settings = new OAuthSettings();

            if (Environment.IsProduction() && string.IsNullOrEmpty(Configuration["SettingsUrl"]))
            {
                throw new Exception("SettingsUrl is not found");
            }

            if (string.IsNullOrEmpty(Configuration["SettingsUrl"]))
            {
                Configuration.Bind(settings);
            }
            else
            {
                settings = SettingsProcessor.Process <OAuthSettings>(Configuration["SettingsUrl"].GetStringAsync().Result);
            }

            services.AddSingleton <IOAuthSettings>(settings);

            services.AddAuthentication(options => { options.SignInScheme = "ServerCookie"; });

            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddCors(options =>
            {
                options.AddPolicy("Lykke", builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials();
                });
            });

            services.AddMvc()
            .AddViewLocalization()
            .AddDataAnnotationsLocalization()
            .AddMvcOptions(o => { o.Filters.Add(typeof(UnhandledExceptionFilter)); });

            services.AddDistributedMemoryCache();

            services.AddAutoMapper();

            services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(30); });

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedProto;
            });

            WebDependencies.Create(services);

            return(ApiDependencies.Create(services, settings));
        }
        private OAuthSettings LoadGoogleSettings()
        {
            var googleSettings = new OAuthSettings
                {
                    Scopes = "", 
                    AuthorizeUrl = "todo",
                    RedirectUrl = "todo"
                };

            return googleSettings;
        }
        private OAuthSettings LoadFacebookSettings()
        {
            var facebookSettings = new OAuthSettings
            {
                Scopes = "", 
                AuthorizeUrl = "https://m.facebook.com/dialog/oauth/",
                RedirectUrl = "http://www.facebook.com/connect/login_success.html"
            };

            return facebookSettings;
        }
        public void uses_the_specified_OAuthSettings()
        {
            var theSettings = new OAuthSettings {
                ConsumerKey = "blah", ConsumerSecret = "private"
            };
            var registry = new FubuRegistry();

            registry.Import <ApplyTwitterAuthentication>(x => x.UseOAuthSettings(theSettings));

            var graph = BehaviorGraph.BuildFrom(registry);

            graph.Services.DefaultServiceFor <OAuthSettings>().Value.ShouldEqual(theSettings);
        }
        /// <summary>
        /// Gets the qb authentication settings.
        /// </summary>
        /// <returns></returns>
        public static OAuthSettings GetQBAuthSettings()
        {
            var authSettings = new OAuthSettings();

            authSettings.ClientId              = QBSettings.Settings.QBClientId;
            authSettings.ClientSecret          = QBSettings.Settings.QBClientSecret;
            authSettings.DiscoveryUrl          = QBSettings.Settings.QBDiscoveryUrl;
            authSettings.RedirectUri           = QBSettings.Settings.QBRedirectUri;
            authSettings.Scope                 = QBSettings.Settings.QBScope;
            authSettings.ServiceContextBaseUrl = QBSettings.Settings.QBServiceContextBaseUrl;

            return(authSettings);
        }
Example #17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // For use in ReadUsingOptionsPattern page
            services.Configure <PositionOptions>(
                Configuration.GetSection(PositionOptions.Position)
                );

            // Register the settings for "OAuthSettings" section as a service for consuming through the DI container
            var settings = new OAuthSettings();

            Configuration.Bind(OAuthSettings.OAuthSection, settings);
            services.AddSingleton(settings);

            services.AddRazorPages();
        }
Example #18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // For use in OptionsPattern page
            services.Configure <PositionOptions>(
                Configuration.GetSection(PositionOptions.Position)
                );

            // Register the settings for MyOAuthConfig section
            var settings = new OAuthSettings();

            Configuration.Bind("OAuthSettings", settings);
            services.AddSingleton(settings);

            services.AddRazorPages();
        }
Example #19
0
        public void LoadOAuthAuthenticator(OAuthSettings settings)
        {
            if (settings.AccessToken.IsNullOrWhitespace() || settings.AccessTokenSecret.IsNullOrWhitespace())
            {
                throw new AuthenticationException("Missing access token or secret. Cannot create Authenticator");
            }

            var consumer = new ConsumerCredentials(settings.ConsumerKey, settings.ConsumerSecret);

            client_.Authenticator = OAuth1Authenticator.ForProtectedResource(
                consumer.Key,
                consumer.Secret,
                settings.AccessToken,
                settings.AccessTokenSecret,
                OAuthSignatureMethod.RsaSha1);
        }
Example #20
0
 public static IEnumerable <Client> GetClient(OAuthSettings settings)
 {
     return(new List <Client>()
     {
         new Client
         {
             AllowedGrantTypes = GrantTypes.ClientCredentials,
             AllowedScopes = { "apiAccess" },
             ClientId = settings.ClientId,
             ClientSecrets =
             {
                 new Secret(settings.ClientSecret.Sha256())
             }
         }
     });
 }
Example #21
0
 public CoreServiceResponse GetClientSettings()
 {
     try
     {
         ApplicationRegistration.Data.Application app = ApplicationRegistrationRepository.GetOneApplicationWhere(c => c.Name == base.ApplicationName);
         return(new CoreServiceResponse
                (
                    OAuthSettingsRepository
                    .OAuthSettingsDatasWhere(c => c.ApplicationIdentifier == app.Cuid && c.ApplicationName == app.Name)
                    .Select(sd => OAuthSettings.FromData(sd))
                    .Select(os => os.CopyAs <OAuthClientSettings>())
                    .ToArray()
                ));
     }
     catch (Exception ex)
     {
         return(new CoreServiceResponse {
             Success = false, Message = ex.Message
         });
     }
 }
Example #22
0
        public App()
        {
            // clientId: Your OAuth2 client id (get from Instagram API management portal)
            // scope: The scopes for the particular API you're accessing. The format for this will vary by API. ("basic" is all you need for this spp)
            // authorizeUrl: The auth URL for the service (at the time of this writing, it's "https://api.instagram.com/oauth/authorize/")
            // redirectUrl: The redirect URL for the service (as you've specified in the Instagram API management portal)

            // If you'd like to know more about how to integrate with an OAuth provider,
            // I personally like the Instagram API docs: http://instagram.com/developer/authentication/

            XamarinAuthSettings =
                new OAuthSettings(
                    clientId: "",
                    scope: "basic",
                    authorizeUrl: "https://api.instagram.com/oauth/authorize/",
                    redirectUrl: "");

            // Hold on to the NavigationPage as a static, so that we can easily access it via App later.
            _NavPage   = new NavigationPage(new ProfilePage());
            Navigation = _NavPage.Navigation;

            // set the app's main page, which in this case is a NAvigationPage.
            MainPage = _NavPage;
        }
Example #23
0
 public RegisterConfigAsServiceForInjectionModel(OAuthSettings settings)
 {
     _settings = settings;
 }
        private bool SaveSettings()
        {
            EditRobotsTxt.SaveRobots();
            BankSettings.SaveData();
            ApiSettings.SaveData();

            bool valid = true;

            if (!NewsSettings.SaveData())
            {
                MsgErr(NewsSettings.ErrMessage);
                valid = false;
            }
            if (!MailSettings.SaveData())
            {
                MsgErr(MailSettings.ErrMessage);
                valid = false;
            }
            if (!GeneralSettings.SaveData())
            {
                MsgErr(GeneralSettings.ErrMessage);
                valid = false;
            }
            if (!SEOSettings.SaveData())
            {
                MsgErr(SEOSettings.ErrMessage);
                valid = false;
            }

            if (!CountersSettings.SaveData())
            {
                MsgErr(CountersSettings.ErrMessage);
                valid = false;
            }

            if (!OrderConfirmationSettings.SaveData())
            {
                MsgErr(OrderConfirmationSettings.ErrMessage);
                valid = false;
            }
            if (!NotifyEmailsSettings.SaveData())
            {
                MsgErr(NotifyEmailsSettings.ErrMessage);
                valid = false;
            }

            if (!OAuthSettings.SaveData())
            {
                MsgErr(OAuthSettings.ErrMessage);
                valid = false;
            }


            if (!CatalogSettings.SaveData())
            {
                MsgErr(CatalogSettings.ErrMessage);
                valid = false;
            }

            if (!DetailsSettings.SaveData())
            {
                MsgErr(DetailsSettings.ErrMessage);
                valid = false;
            }

            if (!TaskSettings.SaveData())
            {
                MsgErr(TaskSettings.ErrMessage);
                valid = false;
            }

            if (!ProfitSettings.SaveData())
            {
                MsgErr(ProfitSettings.ErrMessage);
                valid = false;
            }

            SocialSettings.SaveData();

            return(valid);
        }
Example #25
0
 public OAuthTests(IOptions <OAuthSettings> options, ICreate create, IOAuthClient oauthClient)
 {
     _oauthSettings = options.Value;
     _create        = create;
     _oauthClient   = oauthClient;
 }
Example #26
0
 public OAuthBuilder(IOptions <OAuthSettings> options, IOAuthClient oauthClient)
 {
     _oauthSettings = options.Value;
     _oauthClient   = oauthClient;
 }