Reach a NetSuite RESTlet via OAuth

前端 未结 1 1544
星月不相逢
星月不相逢 2021-02-08 17:26

The goal is to be able to call RESTlets using OAuth-header instead of NLAuth-header from my Java-application. In order to achieve it I took the following steps:

相关标签:
1条回答
  • 2021-02-08 18:03

    The steps seems to be correct as you are able to get consumer and user keys.

    The probable error could be in your java code. I was able to get a successful response from a RESTLet using Java code. I used Scribe-Java as OAuth 1a client library.

    Below is my main method

    OAuthConfig authConfig = new OAuthConfig("CONSUMER_KEY", "CONSUMER_SECRET", null, SignatureType.Header, null, null);
        Token token = new Token("TOKEN_ID", "TOKEN_SECRET");
        OAuth10aServiceImpl auth10aServiceImpl = new OAuth10aServiceImpl(new NetSuiteApi(), authConfig);
        OAuthRequest request = new OAuthRequest(Verb.GET, "RESTLET_URL");
        request.setRealm("NS_ACCOUNT_ID");
        auth10aServiceImpl.signRequest(token, request);
        Response response = request.send();
    

    you will also need to write NetSuiteApi class, as it is required by Scribe. Just, a framework overhead

    import org.scribe.builder.api.DefaultApi10a;
    import org.scribe.model.Token;
    
    public class NetSuiteApi extends DefaultApi10a {
    
    @Override
    public String getAccessTokenEndpoint() {
        // TODO Auto-generated method stub
        return null;
    }
    
    @Override
    public String getAuthorizationUrl(Token arg0) {
        // TODO Auto-generated method stub
        return null;
    }
    
    @Override
    public String getRequestTokenEndpoint() {
        // TODO Auto-generated method stub
        return null;
    }
    
    }
    

    Also, make sure that the user or user's has access to execute the RESTlet in its deployment.

    0 讨论(0)
提交回复
热议问题