Need Help - automating RESTful api with OAuth2

1,719 views
Skip to first unread message

80Vikram

unread,
Dec 22, 2015, 4:09:03 PM12/22/15
to REST assured
Hi All,

In my project , I need to automate RESTful api which need OAuth2 and later need to use that access token for doing CURD calls on API

Please let me know if there is any sample project which I can refer to

Thanks in advance.

Regards,
Vikram

80Vikram

unread,
Dec 23, 2015, 7:06:02 AM12/23/15
to REST assured
I tried below today

curl -H "X-Access-Token: XXXXXX07236415e5afa181211fdd37e4074c9a936ef28cad079137XXXXXX" -H "X-Client-ID: b1e84f01bc7b80f0f482" https://a.wunderlist.com/api/v1/user

this works fine , now I want to achieve same in test case

@Test
    public void oAuth2(){
        given().
               auth().preemptive().oauth2("XXXXXX07236415e5afa181211fdd37e4074c9a936ef28cad079137XXXXXX").
        when().
                get("https://a.wunderlist.com/api/v1/user").
        then().
                statusCode(200);
    }

above always returns 403

How can I pass Client-ID to make is working ?

Thanks,
Vikram

Johan Haleby

unread,
Dec 23, 2015, 7:19:31 AM12/23/15
to rest-a...@googlegroups.com
If that doesn't work then add them as normal headers.

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

80Vikram

unread,
Dec 23, 2015, 8:52:25 AM12/23/15
to REST assured
Hi Johan,

Thanks for reply , below worked for me

@Test
    public void oAuth2(){
        given().headers("X-Access-Token","XXXXXX07236415e5afa181211fdd37e4074c9a936ef28cad079137XXXXXX","X-Client-ID","b1e84f01bc7b80f0f482").   
               auth().oauth2("XXXXXX07236415e5afa181211fdd37e4074c9a936ef28cad079137XXXXXX").

        when().
                get("https://a.wunderlist.com/api/v1/user").
        then().
                statusCode(200);
    }


I will make a demo github project with our public api sooner. It'll be useful to new users of this awesome framework.

Regards,
Vikram

Johan Haleby

unread,
Dec 23, 2015, 10:06:54 AM12/23/15
to rest-a...@googlegroups.com
That sounds really useful. Please ping me once it' done and perhaps we can add a link from the docs.

80Vikram

unread,
Dec 23, 2015, 10:46:25 AM12/23/15
to REST assured
Sure I'll , planning to finish by next week mid.

I will email you , so that you can review and add link in documentation.

Regards,
Vikram

Johan Haleby

unread,
Dec 23, 2015, 10:47:09 AM12/23/15
to rest-a...@googlegroups.com
+1

80Vikram

unread,
Dec 29, 2015, 4:11:02 AM12/29/15
to REST assured
Hi Johan,

Good morning , I've checked in first few test cases automated using your awesome framework.

https://github.com/vikramvi/RESTful-api-automation

Kindly review and let me know , how I can make it more useful for newcomers to API testing ( like me ).

My next goals are; to add more test cases to cover all scenarios of Wunderlist public API and explore framework capabilities.

Thanks & Regards,
Vikram
Reply all
Reply to author
Forward
0 new messages