@@ -119,9 +119,9 @@ public function getNewClientAction()
119
119
120
120
$ request = $ this ->container ->get ('request ' );
121
121
122
+ $ this ->validateAdminUser ($ request );
122
123
$ this ->validateClientName ($ request );
123
124
$ this ->validateUrl ($ request );
124
- $ this ->validateAdminUser ($ request );
125
125
126
126
// Everything ok, now proceed to create the client
127
127
$ clientManager = $ this ->container ->get ('fos_oauth_server.client_manager.default ' );
@@ -192,11 +192,11 @@ private function validateAdminUser(Request $request) {
192
192
if ($ encoder ->isPasswordValid ($ user ->getPassword (), $ password , $ user ->getSalt ())) {
193
193
// Not an Admin
194
194
if (!in_array ('ROLE_ADMIN ' , $ user ->getRoles ())) {
195
- $ this ->logAndThrowError (400 , 'User is not an Admin: ' . $ username , $ this ->get ('translator ' )->trans ('api.show_error_non_admin ' , array (), 'messages ' , $ request ->getLocale ()), $ request ->getLocale ());
195
+ $ this ->logAndThrowError (400 , 'User ' . $ username . ' is not an Admin. Role(s) assigned : ' . implode ( $ user -> getRoles (), ' , ' ) , $ this ->get ('translator ' )->trans ('api.show_error_non_admin ' , array (), 'messages ' , $ request ->getLocale ()), $ request ->getLocale ());
196
196
}
197
197
} else {
198
198
// Password bad
199
- $ this ->logAndThrowError (400 , 'Invalid password : ' . $ username , $ this ->get ('translator ' )->trans ('api.show_error_password ' , array (), 'messages ' , $ request ->getLocale ()), $ request ->getLocale ());
199
+ $ this ->logAndThrowError (400 , 'Password does not match : ' . $ password , $ this ->get ('translator ' )->trans ('api.show_error_password ' , array (), 'messages ' , $ request ->getLocale ()), $ request ->getLocale ());
200
200
}
201
201
} else {
202
202
// Username bad
@@ -262,13 +262,7 @@ public function getRegisterAction()
262
262
$ msg = 'Please check your email to complete the registration. ' ;
263
263
} else {
264
264
$ msg = 'Registration complete. Welcome! ' ;
265
- $ oAuthRtn = $ this ->fetchAccessToken ($ request ->request ->get ('client_id ' ),
266
- $ request ->request ->get ('client_secret ' ),
267
- $ grantType ,
268
- null ,
269
- $ request ->request ->get ('username ' ),
270
- $ request ->request ->get ('password ' ),
271
- $ request ->request ->get ('scope ' ) );
265
+ $ oAuthRtn = $ this ->fetchAccessToken ($ request , $ grantType );
272
266
}
273
267
274
268
$ this ->logMessage (201 , 'User successfully created ' . $ request ->request ->get ('username ' ) );
@@ -738,7 +732,7 @@ public function getAccessTokenAction()
738
732
$ this ->logAndThrowError (400 , 'Unable to obtain Access Token for missing username/password/clientId/clientSecret. ' , $ this ->get ('translator ' )->trans ('api.show_error_server_fault ' , array (), 'messages ' , $ request ->getLocale ()), $ request ->getLocale ());
739
733
}
740
734
741
- $ oAuthRtn = $ this ->fetchAccessToken ($ request , $ clientId , $ clientSecret , $ grantType, null , $ username , $ password , $ scope );
735
+ $ oAuthRtn = $ this ->fetchAccessToken ($ request , $ grantType );
742
736
743
737
$ msg = 'Access Token successfully fetched for ' . $ username ;
744
738
$ this ->logMessage (201 , $ msg );
@@ -781,7 +775,7 @@ public function getRefreshTokenAction()
781
775
$ this ->logAndThrowError (400 , 'Unable to obtain Access Token for missing refresh_token/clientId/clientSecret. ' , $ this ->get ('translator ' )->trans ('api.show_error_server_fault ' , array (), 'messages ' , $ request ->getLocale ()), $ request ->getLocale ());
782
776
}
783
777
784
- $ oAuthRtn = $ this ->fetchAccessToken ($ request , $ clientId , $ clientSecret , $ grantType, $ refreshToken );
778
+ $ oAuthRtn = $ this ->fetchAccessToken ($ request , $ grantType );
785
779
786
780
$ msg = 'Access Token successfully fetched on Refresh Token ' ;
787
781
$ this ->logMessage (201 , $ msg );
@@ -796,8 +790,20 @@ public function getRefreshTokenAction()
796
790
* Fetch oAuth Access Token from oAuth engine.
797
791
*
798
792
*/
799
- private function fetchAccessToken (Request $ request , $ clientId , $ clientSecret , $ grantType, $ refreshToken = null , $ username = null , $ password = null , $ scope = null )
793
+ private function fetchAccessToken (Request $ request , $ grantType )
800
794
{
795
+ $ request = $ this ->container ->get ('request ' );
796
+
797
+ $ data = $ request ->request ->all ();
798
+
799
+ $ clientId = $ data ['client_id ' ];
800
+ $ clientSecret = $ data ['client_secret ' ];
801
+
802
+ $ refreshToken = array_key_exists ('refresh_token ' , $ data ) ? $ data ['refresh_token ' ] : null ;
803
+ $ username = array_key_exists ('username ' , $ data ) ? $ data ['username ' ] : null ;
804
+ $ password = array_key_exists ('password ' , $ data ) ? $ data ['password ' ] : null ;
805
+ $ scope = array_key_exists ('scope ' , $ data ) ? $ data ['scope ' ] : null ;
806
+
801
807
$ client = new OAuth2 \Client ($ clientId , $ clientSecret );
802
808
803
809
// This is a common function for both getAccessTokenAction() and getRefreshTokenAction().
0 commit comments