Custom Authentication
  • 16 Nov 2022
  • Dark
    Light
  • PDF

Custom Authentication

  • Dark
    Light
  • PDF

Article Summary

Why Would I Need Custom Authentication?

There are some types of authentication that may not currently be handled by the adapter libraries. If this is the case, you can request authentication changes, and if possible, the Adapter Team will make those changes in the library. However, it may not be possible to make the changes, or it may be faster for you to make changes in the adapter.js.

The adapter.js has access to all of the settings in the IAP Service Instance Configuration for the adapter via this.allProps variable. So, to get the username provided in the properties.authentication.username field of the IAP Service Instance Configuration for the adapter, you would get the value from this.allProps.authentication.username.

There are some good example adapters that have custom built authentication. This includes all of the aws adapters. In these adapters, you will notice there are one or more authentication methods. The preference would be to add a getAuthorization method that contains the process of authenticating. Then, all of the methods would call this method to authenticate with the other system. This helps to streamline the authentication process and isolate the required code / customizations to the adapter.

Changes to the adapter.js File:

If you want to build custom authentication into your adapter, you will need to make several code changes in the adapter.js.

  • Add getAuthorization into the myIgnore array in the iapGetAdapterWorkflowFunctions so it does not cause unit tests to fail.
  • Adding the getAuthorization method and the login process. It is also helpful for streamlining if this method takes in the paramaters necessary to make the actual request to the other system and if it makes the request.
  • Change all of the methods in the adapter to call the getAuthorization method. This can be done prior to the actual request and the information can be updated in the request object. Or, if you put the actual request in the getAuthorization method, you can replace the request with the call to getAuthorization.
  • Make sure that you also change the way the requests in the genericAdapterRequests are made or they will fail due to authentication issues.

adapter.js Example

  iapGetAdapterWorkflowFunctions(inIgnore) {
    let myIgnore = [
      'healthCheck',
      'iapGetAdapterWorkflowFunctions',
      'iapHasAdapterEntity',
      'iapVerifyAdapterCapability',
      'iapUpdateAdapterEntityCache',
      'hasEntities',
      'getAuthorization'
    ];

.... 
// within getAuthorization, you can get the auth, set the needed auth in the request object and then make the request

  getAuthorization(entity, action, requestObj, translate, dataNeedForAuth, callback) {

        // make the call to authenticate
        return this.requestHandlerInst.identifyRequest('Auth', 'login', dataNeedForAuth, translate, (authData, authError) => {

        // Assign the authData to the proper headers
        Object.assign(requestObj.addlHeaders, authData);

        // make the call with the proper information
        return this.requestHandlerInst.identifyRequest(entity, action, requestObj, translate, callback);

.... 
// Assumes that getAuthorization will make the request to streamline the changes throughout the rest of the adapter.

      return this.getAuthorization('Bucket', 'abortMultipartUpload', reqObj, true, { username: this.allProps.authentication.username, password: this.allProps.authentication.password,  (irReturnData, irReturnError) => {

Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.