Announcement Announcement Module
Collapse
No announcement yet.
How create tokens that tied to user and client Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How create tokens that tied to user and client

    I have a spring oauth2 implementation for my API. I would like to do some testing using JMeter. In order to do that, I would like to write some test code that will generate 1000 users and automatically create a token for them. I will then export these tokens to be used in JMeter when load testing the API. I have one client for them which is already generated and the 1000 users.

    Can someone guide me towards how to create tokens from within JAVA? I do not want to have any UI involved. I think I am looking for a couple of java calls that will create the OAuth2AccessToken which is already bound to the user and the client.

    Thanks

  • #2
    You can ask an OAuth2RestTemplate to acquire an access token for you:

    Code:
    OAuth2AccessToken token = oauth2RestTemplate.getAccessToken();
    The only trick to that is setting up the rest template beforehand with the correct credentials. In you case you can initialize it with a ResourceOwnerPasswordResourceDetails and that should be enough.

    Comment


    • #3
      I try to write this simple code but the last object oauth2RestTemplate do have the method getAccessToken .
      I am using oauth 2.0 1.0.0.M6.

      ResourceOwnerPasswordResourceDetails user =new ResourceOwnerPasswordResourceDetails();
      user.setUsername("");
      user.setPassword("");
      OAuth2RestTemplate oauth2RestTemplate =new OAuth2RestTemplate(user);
      OAuth2AccessToken token = oauth2RestTemplate.getAccessToken();

      Thanks
      Last edited by shai.tap; Apr 16th, 2012, 08:32 AM.

      Comment


      • #4
        M6 doesn't have that feature. Use a snapshot?

        Comment

        Working...
        X