private bool AuthenticateSession(string userName, string password, string hash, ref AuthenticatedSessionInfo sesInfo)
        {
            sesInfo = null;
            var userService    = _injector.Resolve <IStreamingUserService>();
            var sessionService = _injector.Resolve <IStreamingUserSessionService>();

            //userService.CreateUser("zqrtalent", "zqrtalentpass");

            Guid userId;

            if (userService.Authenticate(userName, password, hash, out userId))
            {
                var sInfo = sessionService.StartSession(userId, Request.Host.Value);
                if (sInfo != null)
                {
                    sesInfo = new AuthenticatedSessionInfo
                    {
                        SessionKey     = sInfo.SessionKey,
                        UserId         = userId,
                        UserName       = userName,
                        PlayingMediaId = sInfo.PlayingMediaId,
                        PlayingAtMSec  = sInfo.PlayingAtMSec
                    };
                }
            }
            return(sesInfo != null);
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication("MyAuth")
            .AddScheme <MyAuthSchemeOptions, MyAuthenticationHandler>("MyAuth", options => {
                var authSettings = _di.Resolve <IOptions <AuthSettings> >().Value;
                options.Scheme   = "MyAuth";
                options.AccessTokenKeyHeaderName  = authSettings.AccessTokenHeaderName;
                options.SessionInfoContextKeyName = authSettings.SessionInfoContextKeyName;
                options.Expiration = new TimeSpan((authSettings.ExpirationInMin - authSettings.ExpirationInMin % 60) / 60,
                                                  authSettings.ExpirationInMin % 60, 0);
            });

            services.AddMvc();
            services.AddMemoryCache();

            // Configure settings.
            services.AddOptions();
            services.Configure <GoogleDriveSettings>(_configuration.GetSection("MediaStorage:GoogleDrive"));
            services.Configure <LocalDriveSettings>(_configuration.GetSection("MediaStorage:Local"));
            services.Configure <AuthSettings>(_configuration.GetSection("Auth"));

            // Configure dependency abstructor.
            _di = services.UseMicrosoftDI(_serviceProvider);
            _di.AddSingletone(_configuration);
            _di.AddSingletone(_di);
            _di.AddPerThread <AuthenticationHandler <MyAuthSchemeOptions>, MyAuthenticationHandler>();

            // Start registering services.
            _di.RegisterStorageServices(_hostingEnvironment);
            _di.RegisterMediaDataContextServices();
            _di.RegisterStreamingDataContextServices();
            _di.RegisterCoreServices();
            // End registering services.

            return(_di.Build());
        }