Forum Discussion

Mpeterson's avatar
Mpeterson
Occasional Contributor
12 years ago

Oauth; Differences in Content from Postman?

I am doing oauth api testing and using postman I can do all the calls successfully. However when I try to utilize SoapUIPro 4.6.4 the requests, they fail for invalid token.
I am using the Twitter example as a base, with the event triggering the script from the twitter example

The GET lines are in Postman:

GET /api/20130409/system/institutions HTTP/1.1
Host: qa3appxxxxxx.cloudapp.net
Authorization: OAuth realm="http://qa3xxxxxx.cloudapp.net/api/20130409/system/institutions",oauth_consumer_key="6E65A733-B50B-4BAF-A15F-xxxxxxxxxxxx",oauth_token="4b51464f-e527-4d91-9623-e4183c52fa29",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1389979234",oauth_nonce="QwwBQv",oauth_version="1.0",oauth_signature="EPL9nnAKx3ApbHgiAlXzLfXyMDxxxx"
Cache-Control: no-cache

In SoapUIPro
Authorization: OAuth oauth_consumer_key="6E65A733-B50B-4BAF-A15F-xxxxxxxxxxxxx", oauth_nonce="-3223282616829841309", oauth_signature="1yTGVd6sZo8LTMe1w8SsJVGjo3xxxx", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1389979349", oauth_token="4b51464f-e527-4d91-9623-e4183c52fa29", oauth_version="1.0"

}

I am obviously reaching the host as i get a error reply, I did note the difference in the oauth_nonce value, however Postman works if I post in the value generated by soap.
The script triggered by the event maybe the issue, however I do not really understand what "project" is defined as. I do not see where the item specified are defined to tell what its pointed at.

// get project
def project = com.eviware.soapui.model.support.ModelSupport.getModelItemProject( request )

// initialize OAuth consumer
def consumer = new oauth.signpost.commonshttp.CommonsHttpOAuthConsumer(
project.getPropertyValue( "oauth_consumer_key" ),
project.getPropertyValue( "oauth_consumer_secret" ));

consumer.setTokenWithSecret(
project.getPropertyValue( "oauth_access_token" ),
project.getPropertyValue( "oauth_access_token_secret" ));

// sign the request
consumer.sign( context.httpMethod )

So my question to you is, how is the project defined in the script? Is there a method to emulate the same pattern in the request as is utilized in POSTMAN?
Am I missing something tragically easy?

Mark

6 Replies

  • Mpeterson's avatar
    Mpeterson
    Occasional Contributor
    Ok the content of the HTTP Log:

    Tue Jan 21 07:30:30 MST 2014:DEBUG:>> "GET /api/20130409/system/institutions HTTP/1.1[\r][\n]"
    Tue Jan 21 07:30:30 MST 2014:DEBUG:>> "Accept-Encoding: gzip,deflate[\r][\n]"
    Tue Jan 21 07:30:30 MST 2014:DEBUG:>> "Authorization: OAuth oauth_consumer_key="6E65A733-B50B-4BAF-A15F-B2E9BAXXXXXX", oauth_nonce="-545032362003550119", oauth_signature="cZf8EpxG%2Bl3P1qCvm7FcLv6HXT0%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1390314630", oauth_token="c4032d4e-60ba-44a5-a895-6a697aXXXXXX", oauth_version="1.0"[\r][\n]"
    Tue Jan 21 07:30:30 MST 2014:DEBUG:>> "Host: qa3app3west.cloudapp.net[\r][\n]"
    Tue Jan 21 07:30:30 MST 2014:DEBUG:>> "Connection: Keep-Alive[\r][\n]"
    Tue Jan 21 07:30:30 MST 2014:DEBUG:>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
    Tue Jan 21 07:30:30 MST 2014:DEBUG:>> "[\r][\n]"
    Tue Jan 21 07:30:38 MST 2014:DEBUG:<< "HTTP/1.1 401 Valid token not specified.[\r][\n]"
    Tue Jan 21 07:30:38 MST 2014:DEBUG:<< "Cache-Control: private[\r][\n]"
    Tue Jan 21 07:30:38 MST 2014:DEBUG:<< "Server: Microsoft-IIS/8.0[\r][\n]"
    Tue Jan 21 07:30:38 MST 2014:DEBUG:<< "Access-Control-Allow-Origin: *[\r][\n]"
    Tue Jan 21 07:30:38 MST 2014:DEBUG:<< "X-AspNet-Version: 4.0.30319[\r][\n]"
    Tue Jan 21 07:30:38 MST 2014:DEBUG:<< "X-Powered-By: ASP.NET[\r][\n]"
    Tue Jan 21 07:30:38 MST 2014:DEBUG:<< "Date: Tue, 21 Jan 2014 14:30:39 GMT[\r][\n]"
    Tue Jan 21 07:30:38 MST 2014:DEBUG:<< "Content-Length: 0[\r][\n]"
    Tue Jan 21 07:30:38 MST 2014:DEBUG:<< "[\r][\n]"

    Contents of the error log:

    Tue Jan 21 07:27:09 MST 2014:WARN:Failed to delete temporary project file; C:\Soap Backup\project-temp-9023264614193250820.xml
    Tue Jan 21 07:27:09 MST 2014:WARN:Failed to delete temporary project file; C:\Users\markpeterson\Documents\project-temp-4381663300414293605.xml
    Tue Jan 21 07:27:09 MST 2014:WARN:Failed to delete temporary project file; C:\Soap Backup\project-temp-2218735624394447239.xml
    Tue Jan 21 07:27:09 MST 2014:WARN:Failed to delete temporary project file; C:\Soap Backup\project-temp-7386040741024631583.xml
    Tue Jan 21 07:27:09 MST 2014:WARN:Failed to delete temporary project file; C:\Soap Backup\project-temp-8599433285016194300.xml
    Tue Jan 21 07:27:09 MST 2014:WARN:Failed to delete temporary project file; C:\project-temp-7827789665221553361.xml
    Tue Jan 21 07:32:09 MST 2014:WARN:Failed to delete temporary project file; C:\Soap Backup\project-temp-3028374975021869069.xml
    Tue Jan 21 07:32:09 MST 2014:WARN:Failed to delete temporary project file; C:\Users\markpeterson\Documents\project-temp-3932834926483649858.xml
    Tue Jan 21 07:32:09 MST 2014:WARN:Failed to delete temporary project file; C:\Soap Backup\project-temp-6392826536457569320.xml
    Tue Jan 21 07:32:09 MST 2014:WARN:Failed to delete temporary project file; C:\Soap Backup\project-temp-5977469322833857632.xml
    Tue Jan 21 07:32:09 MST 2014:WARN:Failed to delete temporary project file; C:\Soap Backup\project-temp-7224675094973485687.xml
    Tue Jan 21 07:32:09 MST 2014:WARN:Failed to delete temporary project file; C:\project-temp-3683107121750227572.xml.

    Thanks,
    Mark
  • Hey Mark, sorry for the delayed reply.

    I need to know how far you've gotten in the OAuth process. I assume you're using the Twitter sample project. Have you already:

    1) Set up the required custom project-level properties? These are used by the script to sign the request.
    2) Downloaded the signpost jars and put them in the bin/ext/ folder?

    The project object in the script is the request's corresponding SoapUI project (ie the project where you have defined your OAuth properties). I'm not sure if that answers your question, so if it doesn't, please help me understand and I'll happily assist further.

    Regards,
    Arian
    SmartBear Sweden
  • Mpeterson's avatar
    Mpeterson
    Occasional Contributor
    Ok I am revisiting this issue, I see that the latest version of SoapUIPro (5.1.1) contained a fix for the RequestFilter.filter.request event. So I ran a basic OAuth test and i was pleased to see the header appended to the request, however I note that I have a new error "Receiving response: HTTP/1.1 401 Invalid timestamp 0. Exceeds configured time to live 00:15:00."

    So I did a side by side compare of the OAuth headers values:
    The string produced by Soap is:
    oauth_consumer_key="6E65A733-B50B-4BAF-A15F-XXXXXXXXXXXX", oauth_nonce="-3337028399705576308", oauth_signature="TMuDrjeiH0mab%2FPCUehZtBJ65WI%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1406739280", oauth_token="a166bbd7-3145-4c47-b0d3-dd0c707db047", oauth_version="1.0"

    The string produced by Postman is:
    oauth_consumer_key="6E65A733-B50B-4BAF-A15F-XXXXXXXXXXXX",oauth_token="ca2340d3-3af5-4c0a-990a-15e4cd8ca856",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1406739431",oauth_nonce="TfZ051",oauth_version="1.0",oauth_signature="IbrcWa1G%2B1nWy%2BDtC9or6v7d4g8%3D"

    Both strings have seemly valid values, and do contain a value for time stamp, but they do have two differences in format. The pattern of the data is different, and the soap string contains spaces after the comma prior to each new value. I don't know if that is the actual cause for the host failing to find the value for "timestamp" but i was wondering if there is a method of removing the spaces or altering the data format.

    Thanks,
    Mark
  • Hi,

    Since you already have the string with the header values, you should be able do something like
    new_headers = headers.replace(" ","")
    to remove the spaces.


    Regards,
    Marcus
    SmartBear Support