When building an element that utilizes basic authentication, there are two common approaches to verifying that the user credentials are correct. Note that by default, provisioning an instance using basic authentication, does not verify the user credentials with the provider.
Common Approaches to Basic Authentication
- Provision the instance, then make a subsequent API call to the element to confirm it returns a 200 status code. With this approach, the instance will need to be deleted if the API call does not return success.
- Abstract approach #1 into the element. Benefits of this approach: avoid making the additional call from your backend to Cloud Elements to verify the user credentials, simply make the call the create the instance, and handle success/failure cases. Details below.
We recommend adding a new resource that will make a ‘test’ call to the instance during provisioning. If the call is successful, the credentials are valid and the instance will be provisioned. If the call is unsuccessful, an error will be returned.
- From the element configuration, click Resources
- Add a new resource called on-provision
- Map the new resource to any GET all endpoint
- Select ON PROVISION from the resource type drop down