Hey. I'm trying to understand how the new authentication mechanism works in MVC5 in the SPA template, and it seems to me that they are confusing me. My ultimate goal is to create an API that will be open to SPA, iOS, Android Clients and Windows Phone
Here is what I understand:
I understand that somehow at startup the class decorated with:
[assembly: OwinStartup(typeof(WebApplication1.Startup))]
is a magic call to the ConfigureAuth method:
Inside this method, I have 3 lines of code and inside the constructor of the launch class, I initialized the OAuth authentication options:
static Startup(){ PublicClientId = "self"; UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>()); OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory), AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(14), AllowInsecureHttp = true }; } public void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions()); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); app.UseOAuthBearerTokens(OAuthOptions); }
The first two lines in ConfigureAuth seem to set my application and an external application to use cookies to store authentication status, and the third seems to indicate that it uses media tokens for my application.
From what limited knowledge that I still have about native mobile device applications, I do not understand cookies, and I have to use tokens for authentication.
If so, should the externalSignIn parameter be set for carrier labels instead of an external cookie?
During debugging, I also noticed that in OAuthProvider, the authentication type is actually set for media tokens. If so, what makes this line of code valid:
app.UseCookieAuthentication (new CookieAuthenticationOptions () function);
Some clarification of how this works would be greatly appreciated, I could only find information on the Internet that shows me how to use external logins.