Skip to Content

SAP StreamWork uses OAuth for REST API authorization and authentication. Many developers are new to OAuth which makes it more difficult to understand how to implement. Sample code is almost always the best way to teach a new concept to developers, so I’m creating this code walk through to show how to implement a client that uses the StreamWork REST API. The sample code is Java but should be easily convertible into most languages.

If you just want to learn more OAuth and 12Sprints SAP StreamWork REST API Authentication, Authorization, and OAuth

Step 1 – Register your application

To use the REST API you most first register your application at: https://beta.12sprints.com/oauth_clients When registering your application you need to pay special attention to two fields, “Integration URL” and “Callback URL”. “Integration URL” is the location of where your application is located or where end-users can find out more about your application. “Callback URL” is specific to the OAuth authorization workflow. If you have a web application this is the URL that 12Sprints will redirect to once the end-user has authorized your application. If you are registering a mobile or desktop application that doesn’t support URL callbacks you should leave this field blank.

Once you have registered your application you will be provided with 5 fields that you need for your application. These fields are:

    1. Consumer Key
    2. Consumer Secret
    3. Request Token URL
    4. Access Token URL
    5. Authorize URL

Step 2 – Get a Request Token

Create a URL request to 12Sprints that includes the Consumer Key and Consumer Secret and send the request to the Request Token URL. OAuth requires that you format the URL request very specifically and the documentation specifies what that format should be. To handle the URL formatting we have created a utility class for 12Sprints OAuth called OAuthHelper.java

OAuthHelper.java

bq.

Step 2.1

Set the constants for OAuthHelper.java

Code Snippet from DestopGetRequestToken.java

bq.

Step 2.2

You then use OAuthHelper class to create the URL request to the Request Token URL and submit the request.

+Code Snippet from Get_RequestToken.java +

bq.

You will receive a response that looks like this:

    1. oauth_token=hbO95U0BCCeeDLLHYNlw
    2. &oauth_token_secret=QTVIJxuPtMbVTM3WmK3dGF0p6b6WvaUysBdMfYIa

We call the oauth_token in the response the request token, and the oauth_token_secret we call the request token secret. You need to store these variables for later use with OAuthHelper.

Step 3 – Send the End-User to the Authorization URL

Build a URL with the authorize URL (received when registering your application) and the request token in the query string. Forward or ask your end user to visit the URL in a browser. The URL should look like this:

[https://beta.12sprints.com/oauth/authorize?oauth_token=hbO95U0BCCeeDLLHYNlw | https://beta.12sprints.com/oauth/authorize?oauth_token=hbO95U0BCCeeDLLHYNlw]

Where hbO95U0BCCeeDLLHYNlw is the request token.

Step 4 – The Authorization Process

When the user visits the Authorize URL they will first be required to login, and secondly they will be asked to authorize your application to use the API on their behalf. When they are asked to authorize your application 12Sprints will display the “Integration URL” provided when registering your application. This will allow them to look up more information about your company or application to help them understand who they are giving authorization to.

Step 4.1 Applications with a Callback URL

If you provided a callback URL during registration, 12Sprints will now redirect the user back to the callback URL. 12Sprints will add two values to the querystring of the URL which you must save.

[http://yourserver/redirectpage | http://yourserver/redirectpage] </p><p>[?oauth_token=hbO95U0BCCeeDLLHYNlw&oauth_verifier=T1pBd8QrzYhEAfoOaWxw | https://apis.example.com/?oauth_token=hbO95U0BCCeeDLLHYNlw&oauth_verifier=T1pBd8QrzYhEAfoOaWxw] </p><ul><li>oauth_token –> This is the value of the request token that you already obtained in Step 2. </li><li>aauth_verifier –> This is a new value that you must save in your OAuthHelper class. </li></ul><p>Step 4.2 Applications without a Callback URL </p><p>If you did not provide call back URL during registration, 12Sprints will display the verifier code to the user. You must ask the end user to copy that code and enter it somewhere in your application. This is the OAuth verifier code that is needed by OAuthHelper.java </p><p>Step 5 Replace the Request Token with an Access Token </p><p>In step 2, you should have received a request token and request token secrect. In Step 4 you should have received a verifier code. In Step 5 we use these three variables to request an access token and secret. Set these three variables in your OAuthHelper class and build a URL to request the access token. </p><p>Code Snippet from DesktopGetAccessToken.java+

bq.

Code Snippet from Get_AccessToken.java

bq. AccessToken_URL += oauthHelper.getAccessTokenUrl();
             
               if (Use_proxy){
                    ProxyHelper proxyHelper = new ProxyHelper();
                 SocketAddress address = new InetSocketAddress(proxyHelper.getProxyServer(), proxyHelper.getProxyPort());
                Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
                HttpAccessToken = (HttpURLConnection) new URL (AccessToken_URL).openConnection(proxy);
                HttpURLConnection.setFollowRedirects(true);
                HttpAccessToken.setRequestProperty(“Proxy-Authorization”, “Basic ” + new sun.misc.BASE64Encoder().encode((proxyHelper.getProxyUsername() + “:” +


proxyHelper.getProxyPassword()).getBytes(“UTF-8”)));
               }
               else{
                    HttpAccessToken = (HttpURLConnection)new URL(AccessToken_URL).openConnection();     
               }
             
               HttpAccessToken.setRequestMethod(“POST”); ////This is actually a request, in spite of the class name
               HttpAccessToken.setRequestProperty(“Accept”, “”)               HttpAccessToken.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”);
               response = (InputStream)HttpAccessToken.getContent();

You will receive a response that looks like this:

    1. oauth_token=p66rRR8HVAE0bceLLC2a

&oauth_token_secret=iwKNfnBwg3y2XQwYmEQjNseqwrLmoxV0NGfL6cn9</li></ul><p> In this response we will call the oauth_token the access token, and the oauth_token_secret the access token secret. You need to store these variables. </p><p>Step 6 Make Authorized API Requests*

Now that you have been authorized and you have an access token, and an access token secret you need use these in the URL of all your API requests to 12Sprints. There is a method in the OAuthHelper class called getTestRequestUrl() that will format the URL correctly for you. For this method to work the OAuth helper must have the consumer key, consumer secret, access token, and access token secret values set. Currently this method is hard coded to make requests to /v1/activities.

Snippet from DesktopMakeAPIRequest.java

bq.

Snippet from Make_TestOauthRequest.java

bq.

Step 7 Dealing with Unauthorized Access Tokens

At any time the end-users can revoke authorization to your application. At this point your access token will become unauthorized and you will receive a HTTP 401 Unauthorized response. StreamWork provides a URL to test your access tokens before using them. GET /oauth/test_request For each session you may want to test out your access token before you start to use it. If the access token that you currently have for a user has been revoked, then you can restart the whole authorization process.

Step 8 – Some Important Points that might not be clear in the documentation

  • All API requests must contain the OAuth query string described in Step 6.

I hope this is a good overview of how to use OAuth with the StreamWork REST API, and will help developers quickly and easily build their applications. We are working to build samples for more development languages beyond Java.

Download the full sample code files. Select all the text in the text box and copy it into a code editor.

DesktopGetRequestToken.java

bq. /*—-



Title:  12Sprints Java code samples
Author: Robert Horne
Date:   March 9th 2009

|                                
|This is the first file of three to show how to authorize an application
|OAuth.
| 1. DesktopGetRequestToken.java
| 2. DesktopGetAccessToken.java
| 3. DesktopMakeAPIRequest.java
|
| Each one must be run individually.

| Before you run this file you must fill out in the Variables for
|CONSUMER_KEY and CONSUMER_SECRET.
—-


*/
package com.sap.oauthclient;


import com.sap.oauthlib.Get_RequestToken;
import com.sap.oauthlib.OAuthHelper;


public class DesktopGetRequestToken {


    public static void main(String[] args) throws Exception
    {
         final String CONSUMER_KEY = “”;
         final String CONSUMER_SECRET = “”;
         final String REQUEST_TOKEN_URL = “https://beta.12sprints.com/oauth/request_token“;
         final String ACCESS_TOKEN_URL = “https://beta.12sprints.com/oauth/access_token“;         
 
         final Boolean USE_PROXY = false;
         
        String s = “”;
        OAuthHelper oAuthHelper = new OAuthHelper();
       
        if ( CONSUMER_KEY == null || CONSUMER_SECRET == null) {
             System.out.println( ” You need to add your key and secret to run this application”);
        } else {
             oAuthHelper.setOauthConsumerKey(CONSUMER_KEY);
             oAuthHelper.setOauthConsumerSecret(CONSUMER_SECRET);
             oAuthHelper.setOauthRequestTokenUrl(REQUEST_TOKEN_URL);
             oAuthHelper.setOauthAccessTokenUrl(ACCESS_TOKEN_URL);
                 
             s = Get_RequestToken.Run(oAuthHelper, USE_PROXY);
             System.out.println(s);      
             //Go and run the next sample.
             System.out.println(“When you have authorized the application run the DesktopGetAccessToken.java sample file and use the variables above for the RequestToken and


RequestTokenSecret

“);
        }
    }
}

DesktopGetAccessToken.java <br />

bq. /*—-



Title:  12Sprints Java code samples
Author: Robert Horne
Date:   March 9th 2009

|                                
|This is the second file of three to show how to authorize an application
|OAuth.
| 1. DesktopGetRequestToken.java
| 2. DesktopGetAccessToken.java
| 3. DesktopMakeAPIRequest.java
|
| Each one must be run individually.

| Before you run this file you must fill out in the Variables for
|CONSUMER_KEY, CONSUMER_SECRET, REQUEST_TOKEN, REQUEST_TOKEN_SECRET, and VERIFIER
—-


*/


package com.sap.oauthclient;


import com.sap.oauthlib.Get_AccessToken;
import com.sap.oauthlib.OAuthHelper;


public class DesktopGetAccessToken {
     
    public static void main(String[] args) throws Exception
    {
         final String CONSUMER_KEY = “”;
         final String CONSUMER_SECRET = “”;
         final String ACCESS_TOKEN_URL = “https://beta.12sprints.com/oauth/access_token“; 
         
         //Variables that you get from running DesktopGetRequestToken.java
         //you must hard code these variables
         final String REQUEST_TOKEN = “”;
         final String REQUEST_TOKEN_SECRET = “”;
         final String VERIFIER = “”;
 
         final Boolean USE_PROXY = false;
         
        String s = “”;
        OAuthHelper oAuthHelper = new OAuthHelper();
       
        if ( CONSUMER_KEY == null || CONSUMER_SECRET == null || REQUEST_TOKEN == null) {
             System.out.println( ” You need to add your key and secret to run this application”);
        } else {
             oAuthHelper.setOauthConsumerKey(CONSUMER_KEY);
             oAuthHelper.setOauthConsumerSecret(CONSUMER_SECRET);
             oAuthHelper.setOauthAccessTokenUrl(ACCESS_TOKEN_URL);
             oAuthHelper.setOauthRequestToken(REQUEST_TOKEN);
             oAuthHelper.setOauthRequestSecret(REQUEST_TOKEN_SECRET);
             oAuthHelper.setOauthVerifier(VERIFIER);
                        
             s = Get_AccessToken.Run(oAuthHelper, USE_PROXY);
             System.out.println(s);      
             //Go and run the next sample.
             System.out.println(“You now have an access token and secret. You can use this in all of the rest of your API calls”);
             System.out.println(“Now run DesktopMakeAPIRequestOAuth”);
        }
    }
}

DesktopMakeAPIRequestOAuth.java

bq. /*—-



Title:  12Sprints Java code samples
Author: Robert Horne
Date:   March 9th 2009

|                                
|This is the third file of three to show how to authorize an application
|OAuth.
| 1. DesktopGetRequestToken.java
| 2. DesktopGetAccessToken.java
| 3. DesktopMakeAPIRequest.java
|
| Each one must be run individually.

| Before you run this file you must fill out in the Variables for
|CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, and ACCESS_TOKEN_SECRET
—-


*/
package com.sap.oauthclient;


import com.sap.oauthlib.Make_TestOauthRequest;
import com.sap.oauthlib.OAuthHelper;


public class DesktopMakeAPIRequestOauth {


    public static void main(String[] args) throws Exception
    {
         final String CONSUMER_KEY = “”;
         final String CONSUMER_SECRET = “”;
         
         //Variables that you get from running DesktopGetAccessToken.java
         //you must hard code these variables
         final String ACCESS_TOKEN = “”;
         final String ACCESS_TOKEN_SECRET = “”;
         
         final Boolean USE_PROXY = false;
         
        String s = “”;
        OAuthHelper oAuthHelper = new OAuthHelper();
       
        if ( CONSUMER_KEY == null || CONSUMER_SECRET == null || ACCESS_TOKEN == null) {
             System.out.println( ” You need to add your key and secret to run this application”);
        } else {
             oAuthHelper.setOauthConsumerKey(CONSUMER_KEY);
             oAuthHelper.setOauthConsumerSecret(CONSUMER_SECRET);
             oAuthHelper.setOauthAccessToken(ACCESS_TOKEN);
             oAuthHelper.setOauthAccessTokenSecret(ACCESS_TOKEN_SECRET);
               
             s = Make_TestOauthRequest.Run(oAuthHelper, USE_PROXY);
             System.out.println(s);      
             //Go and run the next sample.
             System.out.println(“You now know how to make API calls with OAuth.”);
        }
    }
}

+Get_RequestToken.java +

bq. /*—-



Title:  12Sprints Java code samples
Author: Anthony Wood
Date:   08/03/2010
Gets a Request Token for a consumer application that’s been registered
on StreamWork. The OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET

 
| constants must be defined in OAuthHelper.java.                           |                                                                      
—-


*/


package com.sap.oauthlib;


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URL;
import java.net.HttpURLConnection;
import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.net.Proxy;


public class Get_RequestToken {
     
     private static DateFormat expiresFormat = new SimpleDateFormat(“E, dd-MMM-yyyy k:m:s ‘GMT'”, Locale.US);
     public static String Run(OAuthHelper oauthHelper, boolean Use_proxy) throws Exception
    {
         String RequestToken_URL = “”;
          final String TITLE = “Get_RequestToken”;         
        String result = TITLE + ”
” +   “—-


” + ”
“;

        HttpURLConnection HttpSessionToken = null;
        InputStream response = null;
              
        try
        {                                     
            RequestToken_URL += oauthHelper.getRequestTokenUrl();
             
            if (Use_proxy){
                 ProxyHelper proxyHelper = new ProxyHelper();
                 SocketAddress address = new InetSocketAddress(proxyHelper.getProxyServer(), proxyHelper.getProxyPort());
                Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
                HttpSessionToken = (HttpURLConnection) new URL (RequestToken_URL).openConnection(proxy);
                HttpURLConnection.setFollowRedirects(true);
                HttpSessionToken.setRequestProperty(“Proxy-Authorization”, “Basic ” + new sun.misc.BASE64Encoder().encode((proxyHelper.getProxyUsername() + “:” +


proxyHelper.getProxyPassword()).getBytes(“UTF-8”)));
            }
            else{
                 HttpSessionToken = (HttpURLConnection) new URL (RequestToken_URL).openConnection();
            }
                          
            HttpSessionToken.setRequestMethod(“POST”);
            HttpSessionToken.setRequestProperty(“Accept”, “application/x-www-form-urlencoded”);           
               response = (InputStream)HttpSessionToken.getContent();           
            result += TITLE + ” response: ” + String.valueOf(HttpSessionToken.getResponseCode()) + ”

“;
           
            String stringResponse = stringifyInputStream(response);
           
            String[] params = stringResponse.split(“&”); 
            Map/*—-



Title:  12Sprints Java code samples
Author: Anthony Wood
Date:   08/03/2010
Gets an Access Token for a consumer application that’s been registered
on StreamWork. The following constants must be defined in

              

OAuthHelper.java.
  1. OAUTH_CONSUMER_KEY
  1. OAUTH_REQUEST_TOKEN
  1. OAUTH_CONSUMER_SECRET
  1. OAUTH_REQUEST_SECRET
  1. OAUTH_VERIFIER

|                                                                          |                                                                      
—-


*/


package com.sap.oauthlib;


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;


public class Get_AccessToken {
     
     private static DateFormat expiresFormat = new SimpleDateFormat(“E, dd-MMM-yyyy k:m:s ‘GMT'”, Locale.US);
     public static String Run(OAuthHelper oauthHelper, boolean Use_proxy) throws Exception
     {
         String AccessToken_URL = “”;
          final String TITLE = “Get_AccessToken”;         
        String result = TITLE + ”
” +   “—-


” + ”
“;

        HttpURLConnection HttpAccessToken = null;
        InputStream response = null;
       
       
        try
        {                                     
               AccessToken_URL += oauthHelper.getAccessTokenUrl();
             
               if (Use_proxy){
                    ProxyHelper proxyHelper = new ProxyHelper();
                 SocketAddress address = new InetSocketAddress(proxyHelper.getProxyServer(), proxyHelper.getProxyPort());
                Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
                HttpAccessToken = (HttpURLConnection) new URL (AccessToken_URL).openConnection(proxy);
                HttpURLConnection.setFollowRedirects(true);
                HttpAccessToken.setRequestProperty(“Proxy-Authorization”, “Basic ” + new sun.misc.BASE64Encoder().encode((proxyHelper.getProxyUsername() + “:” +


proxyHelper.getProxyPassword()).getBytes(“UTF-8”)));
               }
               else{
                    HttpAccessToken = (HttpURLConnection)new URL(AccessToken_URL).openConnection();     
               }
             
               HttpAccessToken.setRequestMethod(“POST”); ////This is actually a request, in spite of the class name
               HttpAccessToken.setDoOutput(true);               
               HttpAccessToken.setRequestProperty(“Accept”, “application/x-www-form-urlencoded”);
               response = (InputStream)HttpAccessToken.getContent();           
            result += TITLE + ” response: ” + String.valueOf(HttpAccessToken.getResponseCode()) + ”

“;                                       
             result += stringifyInputStream(response) + ”

“;          


               result += “Logon cookies:” + ”
“;                                   

               MapMake_TestOauthRequest.java

bq. package com.sap.oauthlib;


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;


public class Make_TestOauthRequest {
     
     private static DateFormat expiresFormat = new SimpleDateFormat(“E, dd-MMM-yyyy k:m:s ‘GMT'”, Locale.US);
     public static String Run(OAuthHelper oauthHelper, boolean Use_proxy) throws Exception
    {
         String TestRequest_Url = “”;
          final String TITLE = “Make_TestOauthRequest”;         
        String result = TITLE + ”
” +   “—-


” + ”
“;

        HttpURLConnection HttpSessionToken = null;
        InputStream response = null;
       
        try
        {  
             TestRequest_Url = “https://beta.12sprints.com/v1/activities“;
               TestRequest_Url += oauthHelper.getTestRequestUrl();
                          
             if (Use_proxy){
                  ProxyHelper proxyHelper = new ProxyHelper();
                 SocketAddress address = new InetSocketAddress(proxyHelper.getProxyServer(), proxyHelper.getProxyPort());
                Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
                HttpSessionToken = (HttpURLConnection) new URL (TestRequest_Url).openConnection(proxy);
                HttpURLConnection.setFollowRedirects(true);
                HttpSessionToken.setRequestProperty(“Proxy-Authorization”, “Basic ” + new sun.misc.BASE64Encoder().encode((proxyHelper.getProxyUsername() + “:” +


proxyHelper.getProxyPassword()).getBytes(“UTF-8”)));
             }
             else{
                  HttpSessionToken = (HttpURLConnection)new URL(TestRequest_Url).openConnection();     
             }
                                                                                      
               HttpSessionToken.setRequestMethod(“GET”);
               HttpSessionToken.setDoOutput(true);               
               HttpSessionToken.setRequestProperty(“Accept”, “application/xml”);
               
               response = (InputStream)HttpSessionToken.getContent();           
            result += TITLE + ” response: ” + String.valueOf(HttpSessionToken.getResponseCode()) + ”

“;                                       
             result += stringifyInputStream(response) + ”

“;           


               result += “Logon cookies:” + ”
“;                                   

               MapOAuthHelper.java

bq. /*—-



Title:  12Sprints Java code samples
Date:   08/03/2010
In this sample, the steps for configuring OAuth to work with OAuth are:

 

1. Register you application at https://streamwork.com/oauth_clients
2. Run Get_RequestToken.java to get a request token from StreamWork
3. Authorize the application at


     https://streamwork.com/oauth/authorize?oauth_token=<request_token>,
     where <request_token> is the key that is issued after Step 2.
4. Run Get_AccessToken.java to exchange the request token for an access
     token.
5. Optionally, run Make_TestOauthRequest.java to make a Test Request to
StreamWork using OAuth.
Once you’ve been issued an access token, all additional API calls to
StreamWork must include the following parameters:

 

  1. oauth_consumer_key — the key that is issued when you register the
          application
  1. oauth_token — the access token that is issued in Step 4.
     

  1. oauth_signature_method — must always be “PLAINTEXT”
     

  1. oauth_signature — the concatenation of the consumer secret that is
           issued     when you register the application and the access and the
           access token secret when you are issued the access token,
           separated by an escaped ampersand (%26)
     

  1. oauth_timestamp — the time of the request, in UNIX time format
     

  1. oauth_nonce — a random string
     

  1. oauth_version — must always be “1.0”

|                                                                          |                                                                         
—-


*/


package com.sap.oauthlib;
import java.math.BigInteger;
import java.security.SecureRandom;


public class OAuthHelper {


    private String oauthRequestTokenUrl = “”;
     private String oauthConsumerKey = “”; //the key that’s issued when a consumer application is registered
    private String oauthConsumerSecret = “”; //the secret that’s issued when a consumer application is registered
    private String oauthRequestToken = “”; //the key that’s issued when Get_RequestToken.java is run
    private String oauthRequestSecret = “”; //the secret that’s issued when Get_RequestToken.java is run
    private String oauthVerifier = “”; //the verifier that’s issued when a consumer application is authorized on StreamWork
    private String oauthAccessTokenUrl = “”;
    private String oauthAccessToken = “”; //the key that’s issued when Get_AccessToken.java is run
    private String oauthAccessTokenSecret = “”; //the secret that’s issued when Get_AccessToken.java is run
    private String oauthTestRequestUrl = “”;
   
    public String getOauthRequestTokenUrl() {
          return oauthRequestTokenUrl;
     }


     public void setOauthRequestTokenUrl(String oauthRequestTokenUrl) {
          this.oauthRequestTokenUrl = oauthRequestTokenUrl;
     }


     public String getOauthConsumerKey() {
          return oauthConsumerKey;
     }


     public void setOauthConsumerKey(String oauthConsumerKey) {
          this.oauthConsumerKey = oauthConsumerKey;
     }


     public String getOauthConsumerSecret() {
          return oauthConsumerSecret;
     }


     public void setOauthConsumerSecret(String oauthConsumerSecret) {
          this.oauthConsumerSecret = oauthConsumerSecret;
     }


     public String getOauthRequestToken() {
          return oauthRequestToken;
     }


     public void setOauthRequestToken(String oauthRequestToken) {
          this.oauthRequestToken = oauthRequestToken;
     }


     public String getOauthRequestSecret() {
          return oauthRequestSecret;
     }


     public void setOauthRequestSecret(String oauthRequestSecret) {
          this.oauthRequestSecret = oauthRequestSecret;
     }


     public String getOauthVerifier() {
          return oauthVerifier;
     }


     public void setOauthVerifier(String oauthVerifier) {
          this.oauthVerifier = oauthVerifier;
     }


     public String getOauthAccessTokenUrl() {
          return oauthAccessTokenUrl;
     }


     public void setOauthAccessTokenUrl(String oauthAccessTokenUrl) {
          this.oauthAccessTokenUrl = oauthAccessTokenUrl;
     }


     public String getOauthAccessToken() {
          return oauthAccessToken;
     }


     public void setOauthAccessToken(String oauthAccessToken) {
          this.oauthAccessToken = oauthAccessToken;
     }


     public String getOauthAccessTokenSecret() {
          return oauthAccessTokenSecret;
     }


     public void setOauthAccessTokenSecret(String oauthAccessTokenSecret) {
          this.oauthAccessTokenSecret = oauthAccessTokenSecret;
     }


     public String getOauthTestRequestUrl() {
          return oauthTestRequestUrl;
     }


     public void setOauthTestRequestUrl(String oauthTestRequestUrl) {
          this.oauthTestRequestUrl = oauthTestRequestUrl;
     }


     
    
    /* Gets the required OAuth parameters when making a call to StreamWork */
    public String getOauthParameters(){
         
          String params = “?oauth_consumer_key=” + oauthConsumerKey +
                         “&oauth_token=” + oauthAccessToken +
                         “&oauth_signature_method=PLAINTEXT” +
                         “&oauth_signature=” + oauthConsumerSecret + “%26” + oauthAccessTokenSecret +
                         “&oauth_timestamp=” + System.currentTimeMillis()/1000 +
                         “&oauth_nonce=” + getNonce() +
                         “&oauth_version=1.0”;
         
          return params;
         
     }
   
     /* Gets the Url and OAuth parameters used when getting a Request Token on StreamWork */
     public String getRequestTokenUrl(){
         
         String Url = oauthRequestTokenUrl + “?oauth_consumer_key=” + oauthConsumerKey +
                         “&oauth_signature_method=PLAINTEXT” +
                         “&oauth_signature=” + oauthConsumerSecret + “%26” +
                         “&oauth_timestamp=” + System.currentTimeMillis()/1000 +
                         “&oauth_nonce=” + getNonce() +
                         “&oauth_version=1.0” +
                         “&oauth_callback=oob”;
         
          return Url;
     }
    
     /* Gets the Url and OAuth parameters used when getting an Access Token on StreamWork */
     public String getAccessTokenUrl(){
         
          String Url = oauthAccessTokenUrl + “?oauth_consumer_key=” + oauthConsumerKey +
                                   “&oauth_token=” + oauthRequestToken +
                                   “&oauth_signature_method=PLAINTEXT” +
                                “&oauth_signature=” + oauthConsumerSecret + “%26” + oauthRequestSecret +
                                “&oauth_timestamp=” + System.currentTimeMillis()/1000 +
                                “&oauth_nonce=” + getNonce() +
                                “&oauth_version=1.0” +
                                “&oauth_verifier=” + oauthVerifier;
         
          return Url;
     }
    
     /* Gets the Url and OAuth parameters used when making a Test Request on StreamWork */
     public String getTestRequestUrl(){
         
          String Url = oauthTestRequestUrl +  “?oauth_consumer_key=” + oauthConsumerKey +
                                   “&oauth_token=” + oauthAccessToken +
                                   “&oauth_signature_method=PLAINTEXT” +
                                   “&oauth_signature=” + oauthConsumerSecret + “%26” + oauthAccessTokenSecret +
                                   “&oauth_timestamp=” + System.currentTimeMillis()/1000 +
                                   “&oauth_nonce=” + getNonce() +
                                   “&oauth_version=1.0”;
         
          return Url;
     }
 
     /* Gets a random string for the oauth_nonce parameter */
     private String getNonce(){
          SecureRandom random = new SecureRandom();
          return new BigInteger(130, random).toString(32);
     }
}

ProxyHelper.java

bq.

 

 

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply