.NET Core Token Auth

https://pioneercode.com/post/authentication-in-an-asp-dot-net-core-api-part-3-json-web-token

However, by default if you do unauthorized request you'll be redirected to /account/login. Whereas for REST API you want to return 401 not authorized instead.

So, you do something like this:

options.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents
{
   OnRedirectToLogin = ctx =>
   {
       if (ctx.Request.Path.StartsWithSegments("/api") &&
           ctx.Response.StatusCode == (int) HttpStatusCode.OK)
       {
           ctx.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
       }
       else
       {
           ctx.Response.Redirect(ctx.RedirectUri);
       }
       return Task.FromResult(0);
   }
};

Ref: https://devblog.dymel.pl/2016/07/07/return-401-unauthorized-from-asp-net-core-api/

 

 

Android Lifecycle

https://stackoverflow.com/questions/28929637/difference-and-uses-of-oncreate-oncreateview-and-onactivitycreated-in-fra