Java SDK Authentication with VersionOne Access Tokens

537 views Asked by At

I am trying to authenticate against my VersionOne instance using the V1 Java SDK and V1 access tokens. I followed the documentation for creating acess tokens and creating a connection in preparation to get this to work.

The problem is that I keep running into a ConnectionException stating a "401 Could not authenticate" message (stack trace below). What could be causing this?


Development Environment

  1. VersionOne Winter '15 (15.0.13.7283) using Windows Integrated Authentication
  2. VersionOne.SDK.Java.APIClient 15.0.0

Source Code

    // build the connector using an access token
    V1Connector connector = V1Connector.withInstanceUrl("https://servername/instancetoauthenticate")
        .withUserAgentHeader("Application", "1.0")
        .withAccessToken("1.WkEciqwKNW7Pnvw9CNmPgQWIdL4=")
        .build();

    // use the connector to instantiate a Services object
    IServices services = new Services(connector);

    // check the logged in member
    Oid oid = services.loggedIn;
    System.out.println("Member Oid: " + oid);

Stack trace

Exception in thread "main" com.versionone.apiclient.exceptions.ConnectionException:
HTTP/1.1 401 Unauthorized error code: 401 Could not authenticate. The VersionOne credentials may be incorrect or the access tokens may have expired.
    at com.versionone.apiclient.V1Connector.manageErrors(V1Connector.java:423)
    at com.versionone.apiclient.V1Connector.getData(V1Connector.java:368)
    at com.versionone.apiclient.Services.retrieve(Services.java:114)
    at com.versionone.apiclient.Services.getLoggedIn(Services.java:254)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty.java:73)
    at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:61)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
    at com.netsuite.versionone.exporttasks.Authenticator.main(Authenticator.groovy:30)
1

There are 1 answers

0
acey.bunch On BEST ANSWER

As of the 15.1.0 version of the Java SDK, you can use an access token to connect to a VersionOne instance, even if that instance is configured to use Windows Integrated Authentication. The trick is to use the new useOAuthEndpoints() method of the V1Connector:

V1Connector connector = V1Connector
    .withInstanceUrl("<Server Base URI>")
    .withUserAgentHeader("AppName", "1.0")
    .withAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
    .useOAuthEndpoints()
    .build();

Note that you only have to use the useOAuthEndpoints() method for NTLM configured instances.

VersionOne Java SDK connection documentation can be found here: https://community.versionone.com/Developers/Developer-Library/Documentation/Java_SDK/Creating_a_Connection