FOSOAuthServerBundle with FOSUserBundle - How to make it works?

后端 未结 1 991
暗喜
暗喜 2021-02-04 20:21

Currently my project works very well. I use FOSUserBundle for the management of my users. Now, I want to implement OAuth, so I\'m using FOSOAuthServerBundle. Most of developers

相关标签:
1条回答
  • 2021-02-04 21:16

    I've just installed this bundle and started playing with it.

    I think you need to learn first more about how OAuth authentication works.

    This way you will understand that the FOSUserBundle mechanisms are not exactly the same as OAuth.

    Your link is the best piece of information to setup correctly the bundle.

    I'm using MongoDB to store all the 4 required documents : Client, AuthCode, RefreshToken and AccessToken

    The step called "Create a new client" is basically the "register" process of FOSUserBundle for OAuth.

    OAuth will use the client to give permission to access.

    The main idea of OAuth is to secure an API, therefore I suggest you switch your config to anonymous: false

    Then you'll see the message :

    {"error":"access_denied","error_description":"OAuth2 authentication required"}

    when you call your API

    The idea of OAuth is to get an Access Token to call your API. Read this : http://blog.tankist.de/blog/2013/07/16/oauth2-explained-part-1-principles-and-terminology/

    This is when the OAuth authentication process needs to be followed.

    There are 5 basic methods to use :

    const GRANT_TYPE_AUTH_CODE = 'authorization_code';
    const GRANT_TYPE_IMPLICIT = 'token';
    const GRANT_TYPE_USER_CREDENTIALS = 'password';
    const GRANT_TYPE_CLIENT_CREDENTIALS = 'client_credentials';
    const GRANT_TYPE_REFRESH_TOKEN = 'refresh_token';
    

    To learn about each, go find more documentation about OAuth RFC.

    Each of them correspond to a specific call to : /oauth/v2/token?client_id=[CLIENT_ID]&response_type=code&redirect_uri=URL&grant_type=token

    Cf: https://github.com/FriendsOfSymfony/oauth2-php/blob/master/lib/OAuth2/OAuth2.php#L182

    Also read this link : blog.tankist.de/blog/2013/08/20/oauth2-explained-part-4-implementing-custom-grant-type-symfony2-fosoauthserverbundle/

    The part "Time to test" explains how to use OAuth.

    I'm still working on it.

    Hope it helps.


    Also this link indicates how to use FOSUserBundle User & UserManager probably to use the password grant_type : If you're authenticating users, don't forget to set the user provider.

    Here's an example using the FOSUserBundle user provider: https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/doc/index.md

    # app/config/config.yml
    fos_oauth_server:
        ...
    
        service:
            user_provider: fos_user.user_manager
    
    0 讨论(0)
提交回复
热议问题