Tag: OAuth in java

How to Generate OAuth Signature for twitter in core JAVA

Twitter.com provides an API for developers to interact with twitter data in their own application,products and services. the twitter API.
is basically a webservice. A developer has to log in or sing up with the twitter platform,register for an API key for his/her application
and use that key to drive interaction on behalf of an authenticated user. visit twitter API Documentation for lmore information on how to utilize the offered service.

Twitter uses OAuth 1.0 Protocol to authenticate API calls of third party applications. OAuth Authentication in twitter API describe how the authentication flow should be.

In this post i’m going to describe how to generate the oauth_signature for twitter request according to The OAuth 1.0 Protocol Section 3.4 Signature in Core Java(mainly for JAVA 1.4 or higher).
The oauth_signature parameter is generated by applying a signing algorithm on all the other request parameters and two secret values.This signature is used for below purposes.

  1. To verify the request has not been modified in transit.
  2. To verify the application sending the request.
  3. To verify that the application is authorized to interact with the resource owner’s account.

Here are the steps of oauth_signature generation algorithm for twitter.

Step 1: Collecting the request method and URL
The first step is to determine the HTTP method and Base URL of the request. For twitter, the HTTP method will either be GET or POST.
The base URL is construced by removing any query string or hash parameters from the URL to which the request is directed. For example consider the following URL which is used as a GET request.

Read More