Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow authenticated users to generate tokens via the UI #1016

Open
wants to merge 1 commit into
base: 7.x-2.x
Choose a base branch
from

Conversation

juampynr
Copy link

@juampynr juampynr commented Mar 14, 2018

I made this addition to the module to make it easier for users to get a token for the API.

Here is what a user would see at its profile:

image

And then, after generating the token:

image

I made this addition to the module to make it easier
for users to get a token for the API.
Copy link
Member

@e0ipso e0ipso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! An awesome feature @juampynr.

Just a couple of minor thoughts.

* @param array $form_state
* The form state array.
*/
function restful_token_auth_generate_token_form_validate($form, &$form_state) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

*/
function restful_token_auth_generate_token_form($form, &$form_state, $uid) {
$form['description'] = array(
'#markup' => t('<p>You don\'t have an API key yet. Click below to generate one.</p>'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid markup in the translation string. Maybe consider #prefix and #suffix for this.

<p>Your authentication token is: <code><?php print $token; ?></code></p>

<p>Discover the API by running the following command in a terminal and replacing
[your-token] by the above string:</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see [your-token] anywhere. Maybe it's a stale comment?


<p>
<code>
curl -H 'access-token:<?php print $token; ?>' <?php print $GLOBALS['base_url'] ?>/api?all=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to have a preprocess function that uses url(…) to set up a variable. Then we only need to print the variable here. The current code will fail if the site is installed in a subdir, or there is a language path prefix, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants