Skip to content

Conversation

iCodr8
Copy link
Contributor

@iCodr8 iCodr8 commented Mar 12, 2017

Documentation for the OAuth2 integration as promised in #180.

@@ -0,0 +1,340 @@
# Adding a OAuth2 authentication using `FOSOAuthServerBundle`
Copy link
Member

Choose a reason for hiding this comment

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

We use Title Case:

Adding a OAuth2 Authentication using `FOSOAuthServerBundle`

@@ -0,0 +1,340 @@
# Adding a OAuth2 authentication using `FOSOAuthServerBundle`

> [OAuth](https://oauth.net/2/) is an open standard for authorization, commonly used as a way for Internet users to authorize websites or applications to access their information on other websites but without giving them the passwords.[1] This mechanism is used by companies such as Google, Facebook, Microsoft and Twitter to permit the users to share information about their accounts with third party applications or websites.
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the [1] please as the reference is not in this document.


public function registerBundles()
{
$bundles = array(
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the short array syntax please?

}
```

## Create oauth2 entites
Copy link
Member

Choose a reason for hiding this comment

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

Creating Entities to Store OAuth2 Data


Add all the following classes to your entities and run `php bin/console doctrine:schema:update --force`:

`AppBundle/Entity/AccessToken.php`
Copy link
Member

Choose a reason for hiding this comment

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

We put the filename as a comment just after <?php directly in the code sample (same for all other files).

$client->setAllowedGrantTypes([$grantType]);
$clientManager->updateClient($client);

$output->writeln(sprintf("<info>The client <comment>%s</comment> was created with <comment>%s</comment> as public id and <comment>%s</comment> as secret</info>",
Copy link
Member

Choose a reason for hiding this comment

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

Can you switch to single quotes?

Add the following code to your `app/config/config.yml` and replace the `clientId` and `clientSecret` with the data from the generated application client with the `client_credentials` grant type.

```yaml
# ...
Copy link
Member

Choose a reason for hiding this comment

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

# app/config/config.yml

# ...
fos_oauth_server:
db_driver: orm # Drivers available: orm, mongodb, or propel
client_class: AppBundle\Entity\Client
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove indentation and put class names into single quotes (it can cause issues without single quotes when the class name contains special chars like \t)

# ...
oauth2:
enabled: true
clientId: 'enter-swagger-api-documentation-client-id'
Copy link
Member

Choose a reason for hiding this comment

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

IMO it should be done using parameters.yml.dist.

```

That's all, now your OAuth2 authentication should work.

Copy link
Member

Choose a reason for hiding this comment

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

Extra line to remove.

@dunglas
Copy link
Member

dunglas commented Mar 20, 2017

This is awesome! Thank you very much for this tutorial it's really appreciated. I just left some minor comments.

Copy link

@Padam87 Padam87 left a comment

Choose a reason for hiding this comment

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

Thanks, works great! (2 small comments from me)

php bin/console oauth:client:create password

# Application client
php bin/console oauth:client:create client_credentials
Copy link

Choose a reason for hiding this comment

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

I think the comments are switched. The 2nd one should be the swagger one.

user_provider: fos_user.user_provider.username
options:
access_token_lifetime: 10800
supported_scopes: user
Copy link

@Padam87 Padam87 May 5, 2017

Choose a reason for hiding this comment

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

This is a bit weird, as it will add ROLE_USER to every authentication, even the client_credentials one, when no user is present.

This may lead to problems... in my case, the user is not allowed to list all users:

    access_control:
        - { path: ^/users, roles: [ ROLE_ADMIN ] }

but it will appear in the docs, and the request fails. I think there should be a hint about this.

Also, from now on user should be null checked even if the ROLE_USER is available.

Choose a reason for hiding this comment

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

Is this ever got into official docs? Installing fresh api-platform, doesn't contain this .md file.
Where is this file located, where we can read the full doc?

Copy link
Member

Choose a reason for hiding this comment

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

The full docs are available here: https://api-platform.com/docs
And also in this GitHub repository.

I really want to merge this one, but it need to be rebased and finished first...

@iCodr8
Copy link
Contributor Author

iCodr8 commented Dec 13, 2018

I do not have the branch anymore and can't fix that.

@iCodr8 iCodr8 closed this Dec 13, 2018
@MelvinLoos
Copy link
Contributor

MelvinLoos commented Mar 6, 2019

Wait so after all this works this never got merged? Is anyone working on oauth integrations docs at all? If not I might have some time on my hands this week and could give it a try

EDIT: Ah looking at the changes I see now that the structure of the documentation has completely changed. So this will need to be completely restructured. @dunglas am I correct in noticing that the index file that was manually edited in this pull request is now dynamically generated based on the markdown files?

@dunglas
Copy link
Member

dunglas commented Mar 7, 2019

The raw text is still available in the diff tab. It would be nice to copy and finish it!

@MelvinLoos
Copy link
Contributor

MelvinLoos commented Mar 7, 2019

Quick response ^^ I added a question in my edited comment above.

And yes I was already looking at https://github.com/api-platform/docs/pull/182.diff to distill the changes.

@bastoune
Copy link

Hi, is this going to be merged ?
Is that doc still relevant ?

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

Successfully merging this pull request may close these issues.

7 participants