I have been researching oauth2 as of recent and trying to draft an implementation plan. However I seem to be missing something, or something hasn't quite clicked yet.
I plan on creating an api and having certain endpoints be protected, requiring authorization. This api will be accessed via my 1rst party web application utilizing javascript/vuejs.
To accomplish this, the "Resource Owner Password Flow" seems to be the best choice for allowing resource owners to authenticate to gain access to parts of the api. The specific implementation I have chosen to use for oauth2 is laravel's "Passport". Example code for the password flow is below as well as the table layout which this implementation uses:
$response = $http->post('http://your-app.com/oauth/token', [
'form_params' => [
'grant_type' => 'password',
'client_id' => 'client-id',
'client_secret' => 'client-secret',
'username' => '[email protected]',
'password' => 'my-password',
'scope' => '',
],
]);
+-------------------------+
|oauth_clients |
+-------------------------+
|id |
|user_id |
|name |
|secret |
|redirect |
|personal_access_client |
|revoked |
|updated_at |
|created_at |
+-------------------------+
+-------------------------+
|oauth_auth_codes |
+-------------------------+
|id |
|user_id |
|client_id |
|scopes |
|revoked |
|expires_at |
+-------------------------+
+-------------------------+
|oauth_access_tokens |
+-------------------------+
|id |
|user_id |
|client_id |
|name |
|scopes |
|revoked |
|created_at |
|updated_at |
|expires_at |
+-------------------------+
+-------------------------+
|oauth_refresh_tokens |
+-------------------------+
|id |
|access_token_id |
|revoked |
|expires_at |
+-------------------------+
+------------------------------+
|oauth_personal_access_clients |
+------------------------------+
|id |
|client_id |
|updated_at |
|created_at |
+------------------------------+
In the example request above, a client_id
and client_secret
are required along with username
and password
. I fail to see how calling http://your-app.com/oauth/token
with the provided parameters would allow a resource owner to authenticate, since there is no table that stores a resource owner's username
and password
.
Could someone explain to me what is happening here, or what pieces of the puzzle I am missing? Should the OAuth2 authorization server be tied to my api (resource server) in some way that allows the authorization server to authenticate user's based on their username and password?...