Giter Site home page Giter Site logo

Comments (4)

kevinchalet avatar kevinchalet commented on August 19, 2024

Hey 😄

Try removing these two things, which are already added by ASP.NET Identity when you call services.AddIdentity()/app.UseIdentity() (with different schemes, which probably explains why Identity cannot see the identity produced by your own cookie/GitHub middleware):

services.Configure<SharedAuthenticationOptions>(options => {
    options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
app.UseCookieAuthentication(options => {
    options.AutomaticAuthentication = true;
    options.AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.LoginPath = new PathString("/account/login");
});

from aspnet.security.oauth.providers.

haythem avatar haythem commented on August 19, 2024

@PinpointTownes, thanks a lot for this great answer. Indeed, adding app.UseCookieAuthentication confuses identity because of the two different schemes. The problem is now solved.

Now, for the scenario where the user is not present in the database, Identity will redirect us to the ExternalLoginConfirmation view, which will ask for the email address if not present in the claims.

I think that we should add to the GitHub middleware the ability of adding an the email claim in the case where the developer adds the user:email scope.

var email = GitHubHelper.GetEmail(payload);
if (!string.IsNullOrEmpty(email))
{
    identity.AddClaim(new Claim(ClaimTypes.Email, email, ClaimValueTypes.String, Options.ClaimsIssuer));
}

I have another question regarding the addition of the claims to the ClaimsIdentity, why are you using AddOptionalClaim instead of simply AddClaim ?

I'll probably submit a PR (though I have to read the contribution guide before 😄 ) by the end of the day regrading the improvement above.

from aspnet.security.oauth.providers.

kevinchalet avatar kevinchalet commented on August 19, 2024

I think that we should add to the GitHub middleware the ability of adding an the email claim in the case where the developer adds the user:email scope.

Good idea! Feel free to submit a PR to fix that 👍

I have another question regarding the addition of the claims to the ClaimsIdentity, why are you using AddOptionalClaim instead of simply AddClaim ?

For readability: AddOptionalClaim internally does exactly what your snippet does, but allows chained calls.

from aspnet.security.oauth.providers.

kevinchalet avatar kevinchalet commented on August 19, 2024

I think that we should add to the GitHub middleware the ability of adding an the email claim in the case where the developer adds the user:email scope.

Done: 23b52e6

from aspnet.security.oauth.providers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.