Client authentication


The Onegini SDK gives the end-developer the flexibility of being in control over building the requests and handling the responses. Therefore, it is your responsibility to perform user authentication by calling OneginiClient#UserClient#authenticateClient whenever a Resource Gateway responds with 401 unauthorized status code. Please refer to the user authentication topic guide to read more about user authentication.

Authenticate client

The DeviceClient#authenticateDevice method performs client authentication. The SDK uses client credentials to request an access token object, which is used to perform anonymous resource calls.

In order to call the authenticateDevice method two arguments have to be passed:

  • String[] scopes the client authentication is requested for,
  • OneginiDeviceAuthenticationHandler interface implementation.

Example implementation

 private void authenticateDevice() {
     OneginiSDK.getOneginiClient(this).getDeviceClient().authenticateDevice(new String[]{ "application-details" }, new OneginiDeviceAuthenticationHandler() {
           public void onSuccess() {
             // fetch anonymous application details

           public void onError(final OneginiDeviceAuthenticationError error) {
             final @OneginiDeviceAuthenticationError.DeviceAuthenticationErrorType int errorType = error.getErrorType();

             if (errorType == OneginiDeviceAuthenticationError.DEVICE_DEREGISTERED) {
               new DeregistrationUtil(InfoActivity.this).onDeviceDeregistered();

When client authentication finishes successfully then onSuccess method will be called. At this point, you can perform anonymous resource calls as described in the next topic.