//public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        //{
        //    app.Map("/SpotifyChangeControl", map => Configure1(map, env, loggerFactory));
        //}

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            //Setup Routes

            //Setup Auth
            //BEGIN RJB 9/10/2016
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage(); //ADDED THIS TO HAVE EXCEPTION PAGES INT MY APP WHEN IT IS IN DEBUG MODE ONLY
            }
            else //WHEN NOT IN DEBUG THEN HAVE SOMETHING COOLER
            {
                app.UseExceptionHandler("/Errors");
                app.UseStatusCodePagesWithRedirects("~/Errors/GetCustomErrorPageToMakeTheStupidHumanFeelGoodAboutThereTecnicalAbilitiesAndReassureThemItsNotTheirFault?sHttpStatus={0}");
                //app.UseStatusCodePagesWithReExecute("/Errors/GetCustomErrorPageToMakeTheStupidHumanFeelGoodAboutThereTecnicalAbilitiesAndReassureThemItsNotTheirFault?sHttpStatus={0}");
            }
            //END RJB 9/10/2016

            app.UseStaticFiles();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge    = true,
                AccessDeniedPath      = new PathString("/Account/Forbidden/"),
                LoginPath             = new PathString("/Account/Login/"),
                LogoutPath            = new PathString("/Account/Logout/")
            });

            SpotifyChangeControlLib.SCCManager oSCCManager = new SpotifyChangeControlLib.SCCManager();
            var Options = new AspNet.Security.OAuth.Spotify.SpotifyAuthenticationOptions()
            {
                ClientId     = oSCCManager.SCC_PUBLIC_ID,
                ClientSecret = oSCCManager.SCC_PRIVATE_ID,
            };

            Options.Scope.Add("playlist-read-private");
            Options.Scope.Add("user-read-private");
            Options.Scope.Add("user-read-email");
            Options.Scope.Add("user-library-read");
            Options.Scope.Add("user-follow-read");
            app.UseSpotifyAuthentication(Options);


            app.UseMvc();
        }
        //public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        //{
        //    app.Map("/SpotifyChangeControl", map => Configure1(map, env, loggerFactory));
        //}
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            //Setup Routes

            //Setup Auth
            //BEGIN RJB 9/10/2016
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage(); //ADDED THIS TO HAVE EXCEPTION PAGES INT MY APP WHEN IT IS IN DEBUG MODE ONLY
            }
            else //WHEN NOT IN DEBUG THEN HAVE SOMETHING COOLER
            {
                app.UseExceptionHandler("/Errors");
               app.UseStatusCodePagesWithRedirects("~/Errors/GetCustomErrorPageToMakeTheStupidHumanFeelGoodAboutThereTecnicalAbilitiesAndReassureThemItsNotTheirFault?sHttpStatus={0}");
               //app.UseStatusCodePagesWithReExecute("/Errors/GetCustomErrorPageToMakeTheStupidHumanFeelGoodAboutThereTecnicalAbilitiesAndReassureThemItsNotTheirFault?sHttpStatus={0}");
            }
            //END RJB 9/10/2016

            app.UseStaticFiles();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge = true,
                AccessDeniedPath = new PathString("/Account/Forbidden/"),
                LoginPath = new PathString("/Account/Login/"),
                LogoutPath = new PathString("/Account/Logout/")
            });

            SpotifyChangeControlLib.SCCManager oSCCManager = new SpotifyChangeControlLib.SCCManager();
            var Options = new AspNet.Security.OAuth.Spotify.SpotifyAuthenticationOptions()
            {
                ClientId = oSCCManager.SCC_PUBLIC_ID,
                ClientSecret = oSCCManager.SCC_PRIVATE_ID,

            };

            Options.Scope.Add("playlist-read-private");
            Options.Scope.Add("user-read-private");
            Options.Scope.Add("user-read-email");
            Options.Scope.Add("user-library-read");
            Options.Scope.Add("user-follow-read");
            app.UseSpotifyAuthentication(Options);

            app.UseMvc();
        }
        protected override async Task <AuthenticationTicket> CreateTicketAsync([NotNull] ClaimsIdentity identity,
                                                                               [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, Options.UserInformationEndpoint);

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);

            var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);

            if (!response.IsSuccessStatusCode)
            {
                Logger.LogError("An error occurred when retrieving the user profile: the remote server " +
                                "returned a {Status} response with the following payload: {Headers} {Body}.",
                                /* Status: */ response.StatusCode,
                                /* Headers: */ response.Headers.ToString(),
                                /* Body: */ await response.Content.ReadAsStringAsync());

                throw new HttpRequestException("An error occurred when retrieving the user profile.");
            }

            var payload = JObject.Parse(await response.Content.ReadAsStringAsync());

            SpotifyChangeControlLib.SCCManager oSCCManager = new SpotifyChangeControlLib.SCCManager();
            string sProfileID   = SpotifyAuthenticationHelper.GetIdentifier(payload);
            string sAuthCode    = request.Headers.Authorization.Parameter;
            string sAccessCode  = tokens.AccessToken;
            string sRefreshCode = tokens.RefreshToken;
            string sTokenType   = tokens.TokenType;
            int    iExpiresIn   = Convert.ToInt32(tokens.ExpiresIn);

            oSCCManager.AddSpotifyUser(sProfileID, sAuthCode, sAccessCode, sRefreshCode, sTokenType, iExpiresIn, DateTime.Now.ToUniversalTime(), DateTime.Now.ToUniversalTime());
            identity.AddOptionalClaim(ClaimTypes.NameIdentifier, SpotifyAuthenticationHelper.GetIdentifier(payload), Options.ClaimsIssuer)
            .AddOptionalClaim(ClaimTypes.Name, SpotifyAuthenticationHelper.GetName(payload), Options.ClaimsIssuer)
            .AddOptionalClaim("urn:spotify:url", SpotifyAuthenticationHelper.GetLink(payload), Options.ClaimsIssuer)
            .AddOptionalClaim("urn:spotify:profilepicture", SpotifyAuthenticationHelper.GetProfilePictureUrl(payload), Options.ClaimsIssuer);

            var principal = new ClaimsPrincipal(identity);
            var ticket    = new AuthenticationTicket(principal, properties, Options.AuthenticationScheme);

            var context = new OAuthCreatingTicketContext(ticket, Context, Options, Backchannel, tokens, payload);
            await Options.Events.CreatingTicket(context);

            return(context.Ticket);
        }
Exemple #4
0
 public ChangesController()
 {
     this._oSCCManager = new SpotifyChangeControlLib.SCCManager();
 }
Exemple #5
0
 public void Configuration(IAppBuilder app)
 {
     //// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
     _oSCCManager = new SpotifyChangeControlLib.SCCManager();
 }
 public ChangesController()
 {
     this._oSCCManager = new SpotifyChangeControlLib.SCCManager();
 }
 public void Configuration(IAppBuilder app)
 {
     //// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
     _oSCCManager = new SpotifyChangeControlLib.SCCManager();
 }