Can't understand aqueduct auto-generated db and auth

516 views Asked by At

I created an Aqueduct project using aqueduct create -t db_and_auth but I did not understand how registration and authentication with OAuth 2.0 works. Can someone explain how to register from OAuth2.0 and DB template auto-created by aqueduct and what steps I have to do to register and then authenticate?

1

There are 1 answers

6
Joe Conway On BEST ANSWER

From a client application, you POST /register with a JSON payload containing a user. Depending on what version of the template you have, this may just be {"username": "bob", "password": "password"} - check the definition of your _User type.

When you are authenticating an already existing user, you invoke POST /auth/token and pass the username, password and other required fields as x-www-form-urlencoded data. The format of that request - written in Dart code - is here: http://aqueduct.io/docs/auth/controllers/.

Whether you are registering a new user or authenticating an existing user, you have to provide a client identifier (and optionally client secret) as a Basic Authorization header. The client identifier must have already been registered with your application and stored in its database.

To store client identifiers in a database, you'll need to first run your application's database migrations on a database instance (see http://aqueduct.io/docs/db/db_tools/ for running database migrations). This will create tables to store OAuth 2.0 client identifiers and tokens.

Then you'll need to add OAuth2.0 client identifiers to your database. This is best accomplished using the aqueduct auth CLI, and there is documentation on it here: http://aqueduct.io/docs/auth/cli/.