@@ -76,58 +76,57 @@ public function authenticate(TokenInterface $token)
7676 // TODO: this is nasty, create a proper interface here
7777 /** @var OAuthToken&TokenInterface&\OAuth2\Model\IOAuth2AccessToken $accessToken */
7878 $ accessToken = $ this ->serverService ->verifyAccessToken ($ tokenString );
79- if (null !== $ accessToken ) {
80- $ scope = $ accessToken ->getScope ();
81- $ user = $ accessToken ->getUser ();
82-
83- if (null !== $ user ) {
84- try {
85- $ this ->userChecker ->checkPreAuth ($ user );
86- } catch (AccountStatusException $ e ) {
87- throw new OAuth2AuthenticateException (
88- OAuth2::HTTP_UNAUTHORIZED ,
89- OAuth2::TOKEN_TYPE_BEARER ,
90- $ this ->serverService ->getVariable (OAuth2::CONFIG_WWW_REALM ),
91- 'access_denied ' ,
92- $ e ->getMessage ()
93- );
94- }
95-
96- $ token ->setUser ($ user );
79+
80+ $ scope = $ accessToken ->getScope ();
81+ $ user = $ accessToken ->getUser ();
82+
83+ if (null !== $ user ) {
84+ try {
85+ $ this ->userChecker ->checkPreAuth ($ user );
86+ } catch (AccountStatusException $ e ) {
87+ throw new OAuth2AuthenticateException (
88+ OAuth2::HTTP_UNAUTHORIZED ,
89+ OAuth2::TOKEN_TYPE_BEARER ,
90+ $ this ->serverService ->getVariable (OAuth2::CONFIG_WWW_REALM ),
91+ 'access_denied ' ,
92+ $ e ->getMessage ()
93+ );
9794 }
9895
99- $ roles = (null !== $ user ) ? $ user ->getRoles () : [];
96+ $ token ->setUser ($ user );
97+ }
98+
99+ $ roles = (null !== $ user ) ? $ user ->getRoles () : [];
100100
101- if (!empty ($ scope )) {
102- foreach (explode (' ' , $ scope ) as $ role ) {
103- $ roles [] = 'ROLE_ ' .mb_strtoupper ($ role );
104- }
101+ if (!empty ($ scope )) {
102+ foreach (explode (' ' , $ scope ) as $ role ) {
103+ $ roles [] = 'ROLE_ ' .mb_strtoupper ($ role );
105104 }
105+ }
106106
107- $ roles = array_unique ($ roles , SORT_REGULAR );
108-
109- $ token = new OAuthToken ($ roles );
110- $ token ->setAuthenticated (true );
111- $ token ->setToken ($ tokenString );
112-
113- if (null !== $ user ) {
114- try {
115- $ this ->userChecker ->checkPostAuth ($ user );
116- } catch (AccountStatusException $ e ) {
117- throw new OAuth2AuthenticateException (
118- OAuth2::HTTP_UNAUTHORIZED ,
119- OAuth2::TOKEN_TYPE_BEARER ,
120- $ this ->serverService ->getVariable (OAuth2::CONFIG_WWW_REALM ),
121- 'access_denied ' ,
122- $ e ->getMessage ()
123- );
124- }
125-
126- $ token ->setUser ($ user );
107+ $ roles = array_unique ($ roles , SORT_REGULAR );
108+
109+ $ token = new OAuthToken ($ roles );
110+ $ token ->setAuthenticated (true );
111+ $ token ->setToken ($ tokenString );
112+
113+ if (null !== $ user ) {
114+ try {
115+ $ this ->userChecker ->checkPostAuth ($ user );
116+ } catch (AccountStatusException $ e ) {
117+ throw new OAuth2AuthenticateException (
118+ OAuth2::HTTP_UNAUTHORIZED ,
119+ OAuth2::TOKEN_TYPE_BEARER ,
120+ $ this ->serverService ->getVariable (OAuth2::CONFIG_WWW_REALM ),
121+ 'access_denied ' ,
122+ $ e ->getMessage ()
123+ );
127124 }
128125
129- return $ token ;
126+ $ token-> setUser ( $ user ) ;
130127 }
128+
129+ return $ token ;
131130 } catch (OAuth2ServerException $ e ) {
132131 throw new AuthenticationException ('OAuth2 authentication failed ' , 0 , $ e );
133132 }
0 commit comments