API Authentication Methods

Hey there! Let Us Talk About API Authentication

If you are just getting started with APIs, you might have heard the term “authentication” thrown around a lot. But what does it mean? Simply put, API authentication is how an API confirms that a request comes from a trusted source before allowing access. This keeps data safe, prevents unauthorized access, and ensures only the right people (or apps) can interact with the system.

The Two Most Common API Authentications in Maya

When working with Maya APIs, you will typically use one of these two authentication methods: Basic Authentication and Bearer Authentication.

A. Basic Authentication

Basic Authentication is one of the simplest ways to authenticate an API request. It works by sending a username and password in the request header. These credentials are encoded in Base64 (which is not the same as encryption!), so it is best to use it over HTTPS to keep things secure.

How it works:

  1. You add an Authorization header to your API request.
  2. The header includes the word "Basic " followed by a Base64-encoded username:password.
  3. The server decodes it, checks if it is valid, and either grants or denies access.

Example Header:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

(That long string is the Base64-encoded version of username:password.)

B. Bearer Authentication

Bearer Authentication (also called Token Authentication) is a secure way to verify your identity when accessing API endpoints. Instead of sending your username and password every time, you use a Bearer Token—a temporary access token obtained after providing the correct credentials.

How it works:

  1. You first request a token from the authentication server.
  2. The token is sent in the Authorization header with every API request.
  3. The server checks if the token is valid before giving access.

Example Header:

Authorization: Bearer your_access_token

(Replace your_access_token with the actual token you received.)

Summary

Understanding API authentication is key to building secure applications. As you work with Maya APIs more, you will see that Basic Authentication is used often, especially in Online Payments Solution. If you are just starting, be sure to check the API specifications to see what API authentication method is used to trigger the request. Happy coding!

Next Steps

Maya recommends reading the supplementary pages below, depending on the Maya Solution you are trying to integrate with.

Read the Basic Authentication page if you are integrating:

  • Maya Online Payments (Maya Checkout, Maya Vault, Pay with Maya)
  • Payments Processing Platform
  • Cash-in to Maya Wallet (Cash-in via Maya Login, Cash-in via Code, Cash-in via Mini App)
  • Remittance to Maya Wallet

Read the Bearer Authentication page if you are integrating:

  • Maya Mini App (for Profile Sharing and Payments only)