AWS cognito user pool - How to get authenticated user session info after successful login?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















How do you get user information after user login from cognito session, or even check if the session is valid?



AWS has a tutorial on how to get that information, HOWEVER, how do you get that information after a redirect on successful login to a different activity? and have access to user data for the current user? The way how AWS tutorial does it is using the onSuccess method and using its arguments CognitoUserDetails cognitoUserDetails however you need cognitoUser to access these information. Below, is AWS's implementation which I have on my redirected Activity.



// Implement callback handler for getting details 
GetDetailsHandler getDetailsHandler = new GetDetailsHandler() {
@Override
public void onSuccess(CognitoUserDetails cognitoUserDetails) {
// The user detail are in cognitoUserDetails
}

@Override
public void onFailure(Exception exception) {
// Fetch user details failed, check exception for the cause
}
};

// Fetch the user details
cognitoUser.getDetailsInBackground(getDetailsHandler);


The way how I have manage to get any user information is by passing some user data with intent to the next activity each time, this seems very unproductive. This is what I have been doing just to get cognitoUser. And username of course is the user data I choose to pass from the previous activity.



CognitoUserPool userPool = new CognitoUserPool(
context, Constants.Pool_Id, Constants.App_client_id,
Constants.App_client_secret, Regions.US_EAST_2
);
CognitoUser cognitoUser = userPool.getUser(username);


In Django I could easily get user data by doing something like request.user on almost any interface. My question is, after successful login is there ANY WAY how to get user data, check if user is logged in, access session data without passing user data to activities each time?










share|improve this question































    0















    How do you get user information after user login from cognito session, or even check if the session is valid?



    AWS has a tutorial on how to get that information, HOWEVER, how do you get that information after a redirect on successful login to a different activity? and have access to user data for the current user? The way how AWS tutorial does it is using the onSuccess method and using its arguments CognitoUserDetails cognitoUserDetails however you need cognitoUser to access these information. Below, is AWS's implementation which I have on my redirected Activity.



    // Implement callback handler for getting details 
    GetDetailsHandler getDetailsHandler = new GetDetailsHandler() {
    @Override
    public void onSuccess(CognitoUserDetails cognitoUserDetails) {
    // The user detail are in cognitoUserDetails
    }

    @Override
    public void onFailure(Exception exception) {
    // Fetch user details failed, check exception for the cause
    }
    };

    // Fetch the user details
    cognitoUser.getDetailsInBackground(getDetailsHandler);


    The way how I have manage to get any user information is by passing some user data with intent to the next activity each time, this seems very unproductive. This is what I have been doing just to get cognitoUser. And username of course is the user data I choose to pass from the previous activity.



    CognitoUserPool userPool = new CognitoUserPool(
    context, Constants.Pool_Id, Constants.App_client_id,
    Constants.App_client_secret, Regions.US_EAST_2
    );
    CognitoUser cognitoUser = userPool.getUser(username);


    In Django I could easily get user data by doing something like request.user on almost any interface. My question is, after successful login is there ANY WAY how to get user data, check if user is logged in, access session data without passing user data to activities each time?










    share|improve this question



























      0












      0








      0








      How do you get user information after user login from cognito session, or even check if the session is valid?



      AWS has a tutorial on how to get that information, HOWEVER, how do you get that information after a redirect on successful login to a different activity? and have access to user data for the current user? The way how AWS tutorial does it is using the onSuccess method and using its arguments CognitoUserDetails cognitoUserDetails however you need cognitoUser to access these information. Below, is AWS's implementation which I have on my redirected Activity.



      // Implement callback handler for getting details 
      GetDetailsHandler getDetailsHandler = new GetDetailsHandler() {
      @Override
      public void onSuccess(CognitoUserDetails cognitoUserDetails) {
      // The user detail are in cognitoUserDetails
      }

      @Override
      public void onFailure(Exception exception) {
      // Fetch user details failed, check exception for the cause
      }
      };

      // Fetch the user details
      cognitoUser.getDetailsInBackground(getDetailsHandler);


      The way how I have manage to get any user information is by passing some user data with intent to the next activity each time, this seems very unproductive. This is what I have been doing just to get cognitoUser. And username of course is the user data I choose to pass from the previous activity.



      CognitoUserPool userPool = new CognitoUserPool(
      context, Constants.Pool_Id, Constants.App_client_id,
      Constants.App_client_secret, Regions.US_EAST_2
      );
      CognitoUser cognitoUser = userPool.getUser(username);


      In Django I could easily get user data by doing something like request.user on almost any interface. My question is, after successful login is there ANY WAY how to get user data, check if user is logged in, access session data without passing user data to activities each time?










      share|improve this question
















      How do you get user information after user login from cognito session, or even check if the session is valid?



      AWS has a tutorial on how to get that information, HOWEVER, how do you get that information after a redirect on successful login to a different activity? and have access to user data for the current user? The way how AWS tutorial does it is using the onSuccess method and using its arguments CognitoUserDetails cognitoUserDetails however you need cognitoUser to access these information. Below, is AWS's implementation which I have on my redirected Activity.



      // Implement callback handler for getting details 
      GetDetailsHandler getDetailsHandler = new GetDetailsHandler() {
      @Override
      public void onSuccess(CognitoUserDetails cognitoUserDetails) {
      // The user detail are in cognitoUserDetails
      }

      @Override
      public void onFailure(Exception exception) {
      // Fetch user details failed, check exception for the cause
      }
      };

      // Fetch the user details
      cognitoUser.getDetailsInBackground(getDetailsHandler);


      The way how I have manage to get any user information is by passing some user data with intent to the next activity each time, this seems very unproductive. This is what I have been doing just to get cognitoUser. And username of course is the user data I choose to pass from the previous activity.



      CognitoUserPool userPool = new CognitoUserPool(
      context, Constants.Pool_Id, Constants.App_client_id,
      Constants.App_client_secret, Regions.US_EAST_2
      );
      CognitoUser cognitoUser = userPool.getUser(username);


      In Django I could easily get user data by doing something like request.user on almost any interface. My question is, after successful login is there ANY WAY how to get user data, check if user is logged in, access session data without passing user data to activities each time?







      android amazon-cognito aws-userpools






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 4:13







      Jam1

















      asked Nov 23 '18 at 4:08









      Jam1Jam1

      306315




      306315
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440542%2faws-cognito-user-pool-how-to-get-authenticated-user-session-info-after-success%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440542%2faws-cognito-user-pool-how-to-get-authenticated-user-session-info-after-success%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?