Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Update authentication documentation
Browse files Browse the repository at this point in the history
The authentication documentation has some examples of REST endpoints
that do not work. This commit resolves this by updating these examples.
  • Loading branch information
cmagnobarbosa committed Oct 15, 2020
1 parent 1bc85d0 commit ec3708a
Showing 1 changed file with 138 additions and 41 deletions.
179 changes: 138 additions & 41 deletions docs/developer/auth.rst
Expand Up @@ -11,82 +11,179 @@ All the authentication, token generation and configuration process is handled
through the REST endpoints that are made available by default on
kytos installation:

This endpoint creates new users:
Creating superusers
===================

.. code-block:: shell
To access the REST Endpoints related to Authentication, it is necessary to
register a first user (Superuser). To do this, run kytos with the -f and -C
arguments:

.. code-block:: shell
$ kytosd -f -C
-----------------------
username: <your_name>
email: <your_email>
password: <your_pass>
re-password: <your_pass>
POST http://127.0.0.1:8181/api/kytos/core/auth/users/
$ curl -X POST \
-H 'Content-Type: application/json' \
-d '{"username":"kytos",
"password":"your_password",
"email": "babel42@email.com"}' \
URL
Login
=====

This endpoint verifies a user and returns a valid token if authentication
is correct:

Endpoint:

.. code-block:: shell
GET /api/kytos/core/auth/login/
Request:

.. code-block :: shell
curl -u username:password http://127.0.0.1:8181/api/kytos/core/auth/login/
Response:

.. code-block:: shell
GET http://127.0.0.1:8181/api/kytos/core/auth/login/
{"token": token_here}
$ curl -X GET \
-H 'Accept:application/json' \
-H 'Authorization:Basic username:password' \
URL
List Users
==========

This endpoint lists the registered users:

Endpoint:

.. code-block:: shell
GET http://127.0.0.1:8181/api/kytos/core/auth/v1/users/
GET /api/kytos/core/auth/users/
Request:

$ curl -X GET \
-H 'Accept:application/json' \
-H 'Authorization: Bearer ${TOKEN}' \
URL
.. code-block :: shell
curl -i http://127.0.0.1:8181/api/kytos/core/auth/users \
-H "Authorization: Bearer token"
Response:

.. code-block:: shell
{"users":[id]}
Get user details
================

This endpoint gets details about a specific user:

Endpoint:

.. code-block:: shell
GET /api/kytos/core/auth/users/<user_id>/
Request:

.. code-block :: shell
curl -i http://127.0.0.1:8181/api/kytos/core/auth/users/<user_id> \
-H "Authorization: Bearer token"
Response:

.. code-block:: shell
{"data":{"email":"user_id@email.com","username":"user_id"}}
Create extra users
==================

This endpoint allows you to create new users:

This endpoint requires a token.

Endpoint:

.. code-block:: shell
GET http://127.0.0.1:8181/api/kytos/core/auth/users/<user_id>/
POST /api/kytos/core/auth/users/
Request:

.. code-block :: shell
curl -d '{"username":"<your_name>", "password":"<pass>",
"email": "<your_email>"}' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer token" \
http://127.0.0.1:8181/api/kytos/core/auth/users/
Response:

.. code-block:: shell
$ curl -X GET \
-H 'Content-type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer ${TOKEN}' \
-d '{"user_id": "001"}' \
URL
User successfully created
Delete a user
=============

This endpoint deletes a specific user.

Endpoint:

.. code-block:: shell
DELETE http://127.0.0.1:8181/api/kytos/core/auth/v1/users/<user_id>/
DELETE /api/kytos/core/auth/users/<user_id>/
Request:

.. code-block :: shell
curl -X DELETE \
-H 'Authorization: Bearer token' \
http://127.0.0.1:8181/api/kytos/core/auth/users/<user_id>
Response:

.. code-block :: shell
$ curl -X DELETE \
-H 'Content-type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer ${TOKEN}' \
-d '{"user_id": "001"}' \
URL
User successfully deleted
Update a user
=============

This endpoint update a specific user:

Endpoint:

.. code-block:: shell
PATCH http://127.0.0.1:8181/api/kytos/core/auth/v1/users/<user_id>/
PATCH /api/kytos/core/auth/users/<user_id>/
Request:

.. code-block :: shell
curl -X PATCH \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer token' \
-d '{"email": "teste2@gmail.com"}' \
http://127.0.0.1:8181/api/kytos/core/auth/users/<user_id>
Response:

$ curl -X PATCH \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ${TOKEN}' \
-d '{"user_id": "001"}' \
URL
.. code-block :: shell
User successfully updated
The process to protect an endpoint is found in session `How to protect a NApp
REST endpoint <https://docs.kytos.io/developer/creating_a_napp/>`_
.
REST endpoint <https://docs.kytos.io/developer/creating_a_napp/>`_.

0 comments on commit ec3708a

Please sign in to comment.