Results 1 to 4 of 4

Thread: How create tokens that tied to user and client

  1. #1
    Join Date
    Apr 2012
    Posts
    8

    Default 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. #2
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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.

  3. #3
    Join Date
    Apr 2012
    Posts
    8

    Default

    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 at 07:32 AM.

  4. #4
    Join Date
    Jun 2005
    Posts
    4,241

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •