Beispiel #1
0
        private SmsAuthenticationOptions GetOptions()
        {
            var result = new SmsAuthenticationOptions();

            if (_properties != null)
            {
                var  message    = string.Empty;
                var  accountSid = string.Empty;
                var  authToken  = string.Empty;
                var  fromNumber = string.Empty;
                bool isSelfProvisioningEnabled = false;
                if (_properties.TryGetValue("Message", out message))
                {
                    result.Message = message;
                }

                if (_properties.TryGetValue("AccountSid", out accountSid))
                {
                    result.TwilioSmsCredentials.AccountSid = accountSid;
                }

                if (_properties.TryGetValue("AuthToken", out authToken))
                {
                    result.TwilioSmsCredentials.AuthToken = authToken;
                }

                if (_properties.TryGetValue("FromNumber", out fromNumber))
                {
                    result.TwilioSmsCredentials.FromNumber = fromNumber;
                }

                if (_properties.TryGetValue("IsSelfProvisioningEnabled", out isSelfProvisioningEnabled))
                {
                    result.IsSelfProvisioningEnabled = isSelfProvisioningEnabled;
                }

                result.ClaimsIncludedInUserCreation = _properties.TryGetArr("ClaimsIncludedInUserCreation");
            }

            return(result);
        }
Beispiel #2
0
        public static IServiceCollection AddSmsAuthentication(this IServiceCollection services, IMvcBuilder mvcBuilder, SmsAuthenticationOptions smsAuthenticationOptions)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (mvcBuilder == null)
            {
                throw new ArgumentNullException(nameof(mvcBuilder));
            }

            if (smsAuthenticationOptions == null)
            {
                throw new ArgumentNullException(nameof(smsAuthenticationOptions));
            }

            var assembly             = typeof(AuthenticateController).Assembly;
            var embeddedFileProvider = new EmbeddedFileProvider(assembly);

            services.Configure <RazorViewEngineOptions>(opts =>
            {
                opts.FileProviders.Add(embeddedFileProvider);
                opts.CompilationCallback = (context) =>
                {
                    var assm            = MetadataReference.CreateFromFile(Assembly.Load("SimpleIdServer.Authenticate.Basic").Location);
                    context.Compilation = context.Compilation.AddReferences(assm);
                };
            });
            services.AddSingleton(smsAuthenticationOptions);
            services.AddAuthBasic();
            services.AddTransient <ITwilioClient, TwilioClient>();
            services.AddTransient <ISmsAuthenticationOperation, SmsAuthenticationOperation>();
            services.AddTransient <IGenerateAndSendSmsCodeOperation, GenerateAndSendSmsCodeOperation>();
            services.AddTransient <IAuthenticateResourceOwnerService, SmsAuthenticateResourceOwnerService>();
            services.AddSingleton <IAuthModule>(new SmsAuthModule());
            mvcBuilder.AddApplicationPart(assembly);
            return(services);
        }