Yii. Add an API Key when connecting to an external resource., How to write the c

Started by land_driver, Jul 18, 2022, 04:11 AM

Previous topic - Next topic

land_driverTopic starter

Yii. Add API Key when connecting to https://api.adm.com/v1/

Option 1 - Via a custom header named API-KEY-1
Option 2 - Via a query string parameter named API-KEY-3

As I understand it, this is done through $APIREST:
$ApiKey='API-KEY';
$C1Url='https://api.adm.com/v1/';
$APIREST = new APIREST($C1Url);
$C2Coins= $APIREST->call(
    array('API-KEY-1:'.$ApiKey)
);

But I'm not strong in programming, which is why I need help on how to properly fit into my code.
<?php

return [
    
'adminEmail' => 'adm@adm.net',
    
'urlApi9' => 'https://api.adm.com/v1/',
    
'urlWm'    => 'https://api2.adm.com/',
];
  •  

titris

This is strange because in the JSON you sent me, the objects have a "name" property.
Let's first understand: what format should the array returned by this method? This function as a whole is written very clumsily, so it's easier for me to understand its logic and rewrite it entirely as it should.
  •  

natmir

The API documentation does not need to explain in detail to external users how authentication works. The lack of explanations of the internal authentication processes is the best practice, since it will be more difficult for hаckers to abuse the API.

Nevertheless, you need to explain the necessary information:

how to get an API key;
how to authenticate a request;
error messages related to incorrect authentication;
sensitivity of authentication information;
the validity period of the access token (authorization).
If there are public and private keys, you need to explain where each key should be used, and note that private keys should not be used together. If different license levels provide different access to API calls, these licensing levels must be explicitly specified in the authorization section or elsewhere.
Since the API Keys section is important, and developers need it before they start using the API, this section should be at the beginning of the guide.
  •