Description
Followed these steps:
- created new integration in magento 2 through admin console.
- Activated the new integration created in first step.
- copied the consumer key and consumer secret.
- using scribe framework, tried to access the request token key , but getting error
Exception in thread "main" org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: 'oauth_problem=Cannot+create+request+token+because+consumer+token+is+not+a+verifier+token'
Can someone help to identify the root cause and the possible rectification?
source code:
package com.cartnship.UsingScribe;
import org.scribe.builder.api.DefaultApi10a;
import org.scribe.model.Token;
API class:
public class MagentoThreeLeggedOAuth extends DefaultApi10a{
public static final String BASE_URL ="http:///magento2/";
@OverRide
public String getAccessTokenEndpoint() {
// TODO Auto-generated method stub
return BASE_URL+"oauth/token/access";
}
@Override
public String getAuthorizationUrl(Token requestToken) {
// TODO Auto-generated method stub
return BASE_URL + "admin/oauth_authorize?oauth_token="+ requestToken.getToken();
}
@Override
public String getRequestTokenEndpoint() {
// TODO Auto-generated method stub
return BASE_URL+"oauth/token/request";
}
}
App class(Main class)
package com.cartnship.UsingScribe;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.concurrent.TimeUnit;
import org.scribe.builder.ServiceBuilder;
import org.scribe.model.SignatureType;
import org.scribe.model.Token;
import org.scribe.oauth.OAuth10aServiceImpl;
import org.scribe.oauth.OAuthService;
public class App
{
public static void main( String[] args )
{
try {
OutputStream stream=new FileOutputStream(new File("D:/output.txt"));
String YOUR_API_KEY="ddv876ki1c8ll417r3qc0wppehefdbwx";
String YOUR_API_SECRET="hpsfvmxdk26442a3vdrp1gkm8yv68d36";
OAuth10aServiceImpl service =(OAuth10aServiceImpl) new ServiceBuilder().provider(MagentoThreeLeggedOAuth.class)
.apiKey(YOUR_API_KEY)
.apiSecret(YOUR_API_SECRET)
.debugStream(stream)
.build();
Token requestToken=service.getRequestToken(60, TimeUnit.SECONDS);
String authorizationUrl=service.getAuthorizationUrl(requestToken);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}