Create Users in Your Application

In the authentication process, the user authenticates through the Identity Provider (IdP), which verifies their identity. Once successfully authenticated, TailorPF queries its database to check if the user’s account already exists.

If the user’s account exists, TailorPF issues an access token, granting the user the appropriate level of access to the requested application based on their roles and permissions.

Here is a diagram that explains the flow of the authentication process. From the client's perspective, the authorization flow is as shown below and uses TailorPF as the authorization server with the Authorization Code Grant.

Steps to Create Users

1. Create a user in Auth0

Log in to your Auth0 account. In the Dashboard, navigate to User management and then select Users. Click Create User to create a new user.

Tutorials – Set up identity provider

2. Use a GraphQL query to create a user in the Tailor DB

Get an access token to use it in the GraphQL playground to run queries.

Run the following commands to get access token.

<span><span style="color: var(--shiki-token-function)">tailorctl</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string)">workspace</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string)">machineuser</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string)">token</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string)">-a</span><span style="color: var(--shiki-color-text)"> ${your_app_name} </span><span style="color: var(--shiki-token-string)">-m</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string)">admin-machine-user</span></span>
<span></span>

Set the token in the Headers section of the playground as follows:

<span><span style="color: var(--shiki-color-text)">{</span></span>
<span><span style="color: var(--shiki-color-text)">  </span><span style="color: var(--shiki-token-keyword)">&quot;Authorization&quot;</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string-expression)">&quot;bearer ${your_access_token}&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>

Seed the data to ensure roles are pre-populated within the Tailor DB. See Seeding Data for more information.

Query the roles to assign a role to the user.

<span><span style="color: var(--shiki-token-keyword)">query</span><span style="color: var(--shiki-color-text)">{</span></span>
<span><span style="color: var(--shiki-color-text)">  roles{</span></span>
<span><span style="color: var(--shiki-color-text)">    edges {</span></span>
<span><span style="color: var(--shiki-color-text)">      node {</span></span>
<span><span style="color: var(--shiki-color-text)">        id</span></span>
<span><span style="color: var(--shiki-color-text)">        name</span></span>
<span><span style="color: var(--shiki-color-text)">      }</span></span>
<span><span style="color: var(--shiki-color-text)">	  }</span></span>
<span><span style="color: var(--shiki-color-text)">  }</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>

You can assign the user a role using its ID.

<span><span style="color: var(--shiki-color-text)">{</span></span>
<span><span style="color: var(--shiki-color-text)">  </span><span style="color: var(--shiki-token-comment)">&quot;data&quot;</span><span style="color: var(--shiki-color-text)">: {</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-comment)">&quot;roles&quot;</span><span style="color: var(--shiki-color-text)">: {</span></span>
<span><span style="color: var(--shiki-color-text)">      </span><span style="color: var(--shiki-token-comment)">&quot;edges&quot;</span><span style="color: var(--shiki-color-text)">: [</span></span>
<span><span style="color: var(--shiki-color-text)">        {</span></span>
<span><span style="color: var(--shiki-color-text)">          </span><span style="color: var(--shiki-token-comment)">&quot;node&quot;</span><span style="color: var(--shiki-color-text)">: {</span></span>
<span><span style="color: var(--shiki-color-text)">          	</span><span style="color: var(--shiki-token-comment)">&quot;id&quot;</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;422e0d2d-fb14-458b-bbb2-db307fc1a174&quot;</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-color-text)">            </span><span style="color: var(--shiki-token-comment)">&quot;name&quot;</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;Admin&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">          }</span></span>
<span><span style="color: var(--shiki-color-text)">        },</span></span>
<span><span style="color: var(--shiki-color-text)">        {</span></span>
<span><span style="color: var(--shiki-color-text)">          </span><span style="color: var(--shiki-token-comment)">&quot;node&quot;</span><span style="color: var(--shiki-color-text)">: {</span></span>
<span><span style="color: var(--shiki-color-text)">            </span><span style="color: var(--shiki-token-comment)">&quot;id&quot;</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;f1292168-f6de-405a-9f5a-c674a239da93&quot;</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-color-text)">            </span><span style="color: var(--shiki-token-comment)">&quot;name&quot;</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;Editor&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">          }</span></span>
<span><span style="color: var(--shiki-color-text)">        }</span></span>
<span><span style="color: var(--shiki-color-text)">      ]</span></span>
<span><span style="color: var(--shiki-color-text)">    }</span></span>
<span><span style="color: var(--shiki-color-text)">  }</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>

Create a user with the email address used in step 1 and assign the 'Editor' role.

<span><span style="color: var(--shiki-token-keyword)">mutation</span><span style="color: var(--shiki-color-text)">{</span></span>
<span><span style="color: var(--shiki-color-text)">  createUser(</span></span>
<span><span style="color: var(--shiki-color-text)">    input: {</span></span>
<span><span style="color: var(--shiki-color-text)">      </span><span style="color: var(--shiki-token-string)">name</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;&lt;username&gt;&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">      </span><span style="color: var(--shiki-token-string)">email</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;&lt;user-email&gt;&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">      </span><span style="color: var(--shiki-token-string)">roles</span><span style="color: var(--shiki-color-text)">: [</span><span style="color: var(--shiki-token-comment)">&quot;f1292168-f6de-405a-9f5a-c674a239da93&quot;</span><span style="color: var(--shiki-color-text)">]</span></span>
<span><span style="color: var(--shiki-color-text)">    }</span></span>
<span><span style="color: var(--shiki-color-text)">  ){</span></span>
<span><span style="color: var(--shiki-color-text)">    id</span></span>
<span><span style="color: var(--shiki-color-text)">  }</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>

The user is created and can now access the application.

Next steps