0

我開發了一個APIRest服務來使用移動應用程序中的數據。我已經使用了Symfony2捆綁包:FOSOAuthServerBundle,FOSUserBundle和FOSRestBundle,並且所有工作都很好,但我需要區分管理面板用戶和api用戶,因爲現在如果我嘗試使用應用的管理員進行身份驗證,我將獲得令牌,但是我只想用api用戶得到一個有效的。如何限制誰可以獲得有效的訪問令牌?

例如,與下一個用戶我應該得到與該第二請求和與所述第一無效授權響應有效令牌,但我獲得有效的令牌與兩者:

管理用戶(ROLE_ADMIN)

https://app.myweb.com/oauth/v2/token?username=adminuser&password=12345&client_id=...&client_secret=...&grant_type=password

APPUSER(ROLE_APP)

https://app.myweb.com/oauth/v2/token?username=appuser&password=12345&client_id=...&client_secret=...&grant_type=password

非常感謝您讓我以正確的方式解決這個問題,並對我的英語感到抱歉。

回答

0

從FOSOAuthServerBundle文檔:

https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/doc/index.md#step-5-configure-fosoauthserverbundle

創建一個用戶,供應商,並將其添加到fos_oauth_server配置:

fos_oauth_server: 
    ... 
    service: 
     user_provider: my_custom_user_provider_service 

創建提供擴展的Symfony \分量\安全\核心\用戶\ UserProviderInterface接口並檢查用戶是否授予了ROLE_APP。這裏記錄:

http://symfony.com/doc/current/cookbook/security/custom_provider.html