|
|
||
|---|---|---|
| src | ||
| .gitignore | ||
| composer.json | ||
| composer.lock | ||
| readme.md | ||
readme.md
ucenter simple authentication API
cURL
curl -X POST \
-H 'Content-Type: application/json; charset=UTF-8'\
-H 'Client-ID: <uuid>'\
-H 'Authorization: Bearer <key>'\
-H 'Accept: application/json'\
-d '{"account": "<account>", "password": "<password>"}'\
https://example.com/api/2nd-part-app/v1/simple-authenticate
<uuid>Application's uuid<key>Application's client secret<account>User's account name, not an email address (user credential)<password>User's password (user credential)
Example
curl -X POST \
-H 'Content-Type: application/json; charset=UTF-8'\
-H 'Client-ID: 2467aff9-5f65-4860-86db-eef597ec3eb6'\
-H 'Authorization: Bearer uuhC1j21nyXhiJfuuluZGmI72n6a8PLkYHn49jY67X7EyGcpLyIgPz7zYTEL'\
-H 'Accept: application/json'\
-d '{"account": "testUser", "password": "userSecret"}'\
https://example.com/api/2nd-part-app/v1/simple-authenticate
PHP example
Setup project
composer install
Run
php src/example.php
API Result
Success
Response status code is 200 OK. Content could be a JSON as following:
{
"ok": true,
"error": null,
"message": "Credential is valid",
"result": true
}
okboolean API is called and running without errorerrorstring (Not used in this API) detail error codemessagestring Human-readable messageresultboolean Authentication result,trueif user credential is correct,falseif user not found or wrong credential
The field result is good to indicate the user credential correctness.
Failed
Response status code is still 200 OK. (Important! Not 401 or 403) But the content could be a JSON as following:
{
"ok": true,
"error": null,
"message": "Credential is invalid or user was suspended",
"result": false
}
Other response
List all probable status code:
401Client UUID or client secret is wrong403Your client is not allowed to call this API, you need to ask the system administrator for more permission404Wrong URL to the API endpoint422User credential format is bad429Exceed the rate limit