Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

SignInManager GetExternalLoginInfoAsync returns null #695

Closed
mlynam opened this issue Dec 30, 2015 · 3 comments
Closed

SignInManager GetExternalLoginInfoAsync returns null #695

mlynam opened this issue Dec 30, 2015 · 3 comments

Comments

@mlynam
Copy link

mlynam commented Dec 30, 2015

I'm using Twitter authentication along with cookie authentication and i'm getting null when the application returns to my ExternalLoginCallback action and asks the SignInManager for the login info. I've registered a callback in the twitter middleware for when the ticket is being created and I've confirmed that I've received an access token from twitter. I've also watched the chatter on fiddler and it looks normal:

  1. Authentication request application side
  2. Application creates a challenge result and redirects the user to the twitter oauth endpoint for authorization.
  3. User authorizes application, twitter returns to the default URL my application provided: /signin-twitter
  4. The application asks for an access token and receives it.
  5. The twitter middleware creates an authentication ticket and redirects to my ExternalLoginCallback action.
  6. Info is null.

Is the cookie not being updated by the twitter middleware...?

I'm kind of at a loss for where to take this. This is a new application templated by VS 2015 update 1. My runtime is 1.0.0-rc1-update1 but all packages are *-rc1-final.

@mlynam
Copy link
Author

mlynam commented Dec 31, 2015

I kept investigating and did something that causes it to work. When I add Identity to my service collection, I am configuring it as follows:

services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
    options.Cookies.ExternalCookieAuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})

this is paired with an AddAuthentication call as follows:

services.AddAuthentication(options =>
{
    options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});

is this the practice I should be using when using cookie authentication, external authentication, and Identity?

@mlynam
Copy link
Author

mlynam commented Dec 31, 2015

I've continued reviewing the src and found that when I add the Twitter authentication middleware, I can set the SignInScheme via the options callback to

app.UseTwitterAuthentication(options =>
{
    ...
    options.SignInScheme = typeof(IdentityCookieOptions).Namespace + ".External";
    ...
}

Which is the default string used in the IdentityCookieOptions class for the external cookie authentication scheme.
This configuration works as well (I removed the options callback when adding Identity to my service collection). I'm still unsure of the best practice.

@HaoK
Copy link
Member

HaoK commented Jan 13, 2016

You basically are bypassing the external cookie when you do this

options.Cookies.ExternalCookieAuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme;

The UseIdentity call is registering two cookie middlewares, one for the ApplicationCookie and one for the ExternalApplicationCookie. These are set to different authentication schemes by default. It should just work if you remove all of these explicit authentication scheme settings and rely on the default values... In general you shouldn't have to change these, but they are mutable since you are free to change them, as long as you set them all to the same values wherever they are used, if you miss setting one, the external login info will be null...

@HaoK HaoK closed this as completed Jan 13, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants