• Shakthi
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

I have succesfully implemented REST API using oAuth in PHP application.

but i got error has occured during authentication.

 

Here with i showed my Coding

 

Initial request :

<?php

$token_url = LOGIN_URI . "/services/oauth2/token";
$curl = curl_init($token_url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

print_r($json_response);

?>

 

i get the Response :

Array
(
    [id] => https://login.salesforce.com/id/00D90000000Y2YTEA0/00590000000hoxcAAA
    [issued_at] => 1311080724805
    [refresh_token] => 5Aep8617VFpoP.M.4tKc.wsyE74IvVIhBvqtmPoh2taT_UxhUv_nV7O2gR6LBFQ_bixsqEhRzQ30w==
    [instance_url] => https://ap1.salesforce.com
    [signature] => FmkAs7jSP5HfV5XsSQDn+ONH+g0aO1uuS0Eso+YHzk4=
    [access_token] => 00D90000000Y2YT!AQ0AQAUzLVIubiAC7UnJtfo4V0r2gYQAwhr_5y6YkEJSX2R9Hc8JFgiPkYpCdh.RAz2BfdFKqg6sVfRhw6ct8g.f9zR32pab
)

 

using above access token, signataure i have formed the variable like

 

<?php

 $post_fields = array(
        'oauth_consumer_key' => '3MVG9Y6d_Btp4xp7PTQjzE8zY.4NJLD95rfMz3_fFk4_Oqb7ZMGMkx7CWHEVg3gRDhrtVUljTU3WZCnkvVWFo',
        'oauth_token' => $access_token,
        'oauth_signature_method' => 'HMAC-SHA1',
        'oauth_signature' => $signature,
        'oauth_timestamp' => $issued_at,
        'oauth_nonce' => $id,
        'oauth_version' => '1.0'
    );


   $token_url = "$instance_url/services/OAuth/u/v20.0";
    $curl = curl_init($token_url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER,array("Authorization: OAuth $access_token"));
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($curl, CURLOPT_POST, TRUE);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

    $json_response = curl_exec($curl);
echo '<pre>';print_r($json_response);

?>

 

and i get the Error like

 

"LOGIN_OAUTH_UNEXPECTED_ERRORAn unexpected error has occured during authentication. Please try again."

 

anyone please help me to proceed further

 

thanks in advance

 

I have succesfully implemented REST API using oAuth in PHP application.

but i got error has occured during authentication.

 

Here with i showed my Coding

 

Initial request :

<?php

$token_url = LOGIN_URI . "/services/oauth2/token";
$curl = curl_init($token_url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

print_r($json_response);

?>

 

i get the Response :

Array
(
    [id] => https://login.salesforce.com/id/00D90000000Y2YTEA0/00590000000hoxcAAA
    [issued_at] => 1311080724805
    [refresh_token] => 5Aep8617VFpoP.M.4tKc.wsyE74IvVIhBvqtmPoh2taT_UxhUv_nV7O2gR6LBFQ_bixsqEhRzQ30w==
    [instance_url] => https://ap1.salesforce.com
    [signature] => FmkAs7jSP5HfV5XsSQDn+ONH+g0aO1uuS0Eso+YHzk4=
    [access_token] => 00D90000000Y2YT!AQ0AQAUzLVIubiAC7UnJtfo4V0r2gYQAwhr_5y6YkEJSX2R9Hc8JFgiPkYpCdh.RAz2BfdFKqg6sVfRhw6ct8g.f9zR32pab
)

 

using above access token, signataure i have formed the variable like

 

<?php

 $post_fields = array(
        'oauth_consumer_key' => '3MVG9Y6d_Btp4xp7PTQjzE8zY.4NJLD95rfMz3_fFk4_Oqb7ZMGMkx7CWHEVg3gRDhrtVUljTU3WZCnkvVWFo',
        'oauth_token' => $access_token,
        'oauth_signature_method' => 'HMAC-SHA1',
        'oauth_signature' => $signature,
        'oauth_timestamp' => $issued_at,
        'oauth_nonce' => $id,
        'oauth_version' => '1.0'
    );


   $token_url = "$instance_url/services/OAuth/u/v20.0";
    $curl = curl_init($token_url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER,array("Authorization: OAuth $access_token"));
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($curl, CURLOPT_POST, TRUE);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

    $json_response = curl_exec($curl);
echo '<pre>';print_r($json_response);

?>

 

and i get the Error like

 

"LOGIN_OAUTH_UNEXPECTED_ERRORAn unexpected error has occured during authentication. Please try again."

 

anyone please help me to proceed further

 

thanks in advance

 

Hi -

 

I have been trying for over a week now to get oauth working between salesforce and my application.  I have experience getting oauth to work with Twitter and Youtube, so I figured this would be easy... 

 

BTW, I have set up Remote Access in my salesforce setup.  

 

I'm having problems on the very first step of the oauth process. This is what I am sending to get the RequestToken (I added the returns for clarity after the &'s)

 

https://login.salesforce.com/_nc_external/system/security/oauth/RequestTokenHandler?oauth_consumer_key=<My key>&
oauth_nonce=8114382&
oauth_signature_method=HMAC-SHA1&
oauth_timestamp=1266716665&
oauth_version=1.0&
oauth_callback=https%3A%2F%2Fwww.catchthecloud.com%2FSalesforceOAuth.aspx&
oauth_signature=fH85OWR29G3IXSp1sc3uf4WMD7w%3D

 

This seems to be correct as per: https://ap1.salesforce.com/help/doc/user_ed.jsp?loc=help&section=help&hash=access_data&target=remoteaccess_authenticate.htm

 

However, I'm getting a 400 - bad request error when sending it.  I'm also having problems sending it via POST, or if I put it in an Authorization header...

 

The C# code that I am using to generate this string is as follows:

 

   

Uri uri = new Uri("https://login.salesforce.com/");
string nonce = this.GenerateNonce();
string timeStamp = this.GenerateTimeStamp();

//Generate Signature
string sig = this.GenerateSignature(uri,
this.ConsumerKey,
this.ConsumerSecret,
this.Token,
this.TokenSecret,
method.ToString(),
timeStamp,
nonce,
out outUrl,
out querystring);

querystring += "&" + this.UrlEncode("oauth_callback") + "=" + this.UrlEncode("https://www.catchthecloud.com/SalesforceOAuth.aspx");
querystring += "&" + this.UrlEncode("oauth_signature") + "=" + this.UrlEncode(sig);

NameValueCollection oauthtokendata = null;
HttpWebRequest request = System.Net.WebRequest.Create(url+"?"+querystring) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
using (TextReader reader = new StreamReader(response.GetResponseStream()))
{
oauthtokendata = HttpUtility.ParseQueryString(reader.ReadToEnd());
}
}

 

Towards the bottom of this code, I do a call to request.GetResponse(), and that's where it dies.  If I take the string that's been created and stick it in the address bar of a browser, I get the following response:

 

 1702Failed: Missing Consumer Key Parameter

 

 

On the first line of this code, --
Uri uri = new Uri("https://login.salesforce.com/");

 

 

 I have used several variations of Uri's in attempts to make this work, including https://login.salesforce.com/_nc_external/system/security/oauth/RequestTokenHandler, but nothing seems to work.

 

 

 

 

 

 

So -- hopefully someone can give me a tip to get this thing to work... I feel like I'm pretty close!

 

 

 

Thanks,

Beth