Giter Club home page Giter Club logo

Comments (7)

assyadh avatar assyadh commented on May 31, 2024

Can you try using this overload:

https://github.com/aws/aws-aspnet-cognito-identity-provider/blob/master/src/Amazon.AspNetCore.Identity.Cognito/CognitoSigninManager.cs#L103

You may want to call something like

var user = await _userManager.FindByNameAsync(login.UserName);

Then this overload:

https://github.com/aws/aws-aspnet-cognito-identity-provider/blob/master/samples/Samples/Areas/Identity/Pages/Account/ResetPassword.cshtml.cs#L69

The user variable should be then updated with the tokens.

Iirc there is a behavior in Identity where you need to be in another page to recoup the tokens from the Context object.

from aws-aspnet-cognito-identity-provider.

ayongbannayan avatar ayongbannayan commented on May 31, 2024

Thank you for the help,

I tried both FindByNameAsync and FindByEmailAsync and while they do return the user object SessionsTokens is null.

Regarding moving to another page this did work for me.

public class DashboardController : Controller
{
    private readonly ILogger<DashboardController> _logger;

    public DashboardController(ILogger<DashboardController> logger)
    {
        _logger = logger;
    }

    [Authorize]
    public async Task<IActionResult> Index()
    {
        var accessToken = await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken);
        var refreshToken = await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.RefreshToken);
        var idToken = await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.IdToken);
 
        var claims = HttpContext.User.Claims;

        return View();
    }
}

All tokens and claims are loaded here. So I'm assuming at this point not having access to claims and token at login is a Microsoft identity issue.

from aws-aspnet-cognito-identity-provider.

assyadh avatar assyadh commented on May 31, 2024

Yes, the context object is updated when accessing another page.

from aws-aspnet-cognito-identity-provider.

assyadh avatar assyadh commented on May 31, 2024

The user instance Session Tokens should be updated after calling the PasswordSigningAsync. Can you check that?

from aws-aspnet-cognito-identity-provider.

ayongbannayan avatar ayongbannayan commented on May 31, 2024
var user = await _signInManager.UserManager.FindByEmailAsync(login.UserName);
var result = await _signInManager.PasswordSignInAsync(user, login.Password, login.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
    _logger.LogInformation("User logged in.");
    return LocalRedirect(returnUrl);
}

If I sign in like above, the session tokens are populated, however there is no way that I see to get the CognitoUser with populated session tokens when using the overload from the sample.

This raises another question for me, when I need to refresh the access token/id token using the refreshtoken the method RefreshSigninAsync requires a CognitoUser, does this user need to have SessionToken populated? I can get a CognitoUser from the user manager but session token is empty. Do I manually create session token from HttpContext or is there a mechanism to get the currently logged in user.

from aws-aspnet-cognito-identity-provider.

assyadh avatar assyadh commented on May 31, 2024

Would you mind sharing a sample app that reproduce the error? Please make sure to not include secrets.

As you can see below, we populate the user tokens from the Context when calling UserManager.GetUserFrom* methods:

https://github.com/aws/aws-aspnet-cognito-identity-provider/blob/master/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserManager.cs#L136

This is also called by the RefreshSigninAsync method so the tokens should be populated.

from aws-aspnet-cognito-identity-provider.

klaytaybai avatar klaytaybai commented on May 31, 2024

Closing due to inactivity

from aws-aspnet-cognito-identity-provider.

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.