Access Using JWT and API Key

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsAccess Using JWT and API Key
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=== Tutorial ===
+
For non-admin users, DreamFactory APIs should be consumed with a JWT (token) from an authenticated session and an application API key. The session token tells the system which user is making the request. The API key tells the system which app is making the request. Each user can be assigned their own role for each app. If no role is assigned, they inherit the default role for the app, as if it was an unauthenticated request. The system will use the session token and API key to determine the role for the current user (for the current app), and limit access to what is allowed by that role. If you get a 'Role not found.' error, make sure you are specifying an API key in addition to the session token.
  
You can consume DreamFactory 2.0 APIs by providing the combination of JWT and API Key. This is more appropriate in case
+
Request:
of a non-admin user. When consuming APIs using JWT and application API Key, access is limited by the role assigned to the
+
user for the application of the API Key being used. Admin users always have access to all APIs using just the JWT.
+
  
=== API Endpoints ===
+
<pre>GET https://foo.com/api/v2/db/_table?session_token=abc.123.efg&api_key=xyz123abc</pre>
 +
* HTTP method: GET
 +
* URL: https://foo.com/api/v2
 +
* Service: db
 +
* Resource: _table
 +
* Session token: abc.123.efg
 +
* API key: xyz123abc
  
<pre>{Method} https://{url}/api/v2/{service}/{resource}?session_token={JWT}&api_key={api-key}</pre>
+
'''Note:''' Session token can also be supplied using the X-DreamFactory-Session-Token request header. API key can also be supplied using the X-DreamFactory-Api-Key request header.
 
+
-- OR --
+
 
+
<pre>{Method} https://{url}/api/v2/{service}/{resource}</pre>
+
Request header
+
<pre>
+
...
+
X-DreamFactory-Session-Token: {JWT}
+
X-DreamFactory-Api-Key: {api_key}
+
...
+
</pre>
+
 
+
=== Example - Using URL parameter ===
+
 
+
* Service: system
+
* Resource: user
+
* Session Token: abc.123.efg
+
* API Key: abc123efg
+
* Method: GET
+
* Request URL:
+
<pre>GET https://foo.com/api/v2/system/user?session_token=abc.123.efg&api_key=abc123efg</pre>
+
 
+
=== Example - Using request header ===
+
 
+
* Service: system
+
* Resource: user
+
* Session Token: abc.123.efg
+
* API Key: abc123efg
+
* Method: GET
+
* Request Header:
+
<pre>
+
...
+
X-DreamFactory-Session-Token: abc.123.efg
+
X-DreamFactory-Api-Key: abc123efg
+
...
+
</pre>
+
* Request URL:
+
<pre>GET https://foo.com/api/v2/system/user</pre>
+

Latest revision as of 18:18, 13 July 2018

For non-admin users, DreamFactory APIs should be consumed with a JWT (token) from an authenticated session and an application API key. The session token tells the system which user is making the request. The API key tells the system which app is making the request. Each user can be assigned their own role for each app. If no role is assigned, they inherit the default role for the app, as if it was an unauthenticated request. The system will use the session token and API key to determine the role for the current user (for the current app), and limit access to what is allowed by that role. If you get a 'Role not found.' error, make sure you are specifying an API key in addition to the session token.

Request:

GET https://foo.com/api/v2/db/_table?session_token=abc.123.efg&api_key=xyz123abc
  • HTTP method: GET
  • URL: https://foo.com/api/v2
  • Service: db
  • Resource: _table
  • Session token: abc.123.efg
  • API key: xyz123abc

Note: Session token can also be supplied using the X-DreamFactory-Session-Token request header. API key can also be supplied using the X-DreamFactory-Api-Key request header.