@@ -83,6 +83,9 @@ AuthorizeHandler.prototype.handle = function(request, response) {
8383 return Promise . reject ( new AccessDeniedError ( 'Access denied: user denied access to application' ) ) ;
8484 }
8585
86+ // Extend model object with request
87+ this . model . request = request ;
88+
8689 var fns = [
8790 this . getAuthorizationCodeLifetime ( ) ,
8891 this . getClient ( request ) ,
@@ -101,13 +104,19 @@ AuthorizeHandler.prototype.handle = function(request, response) {
101104
102105 return Promise . bind ( this )
103106 . then ( function ( ) {
104- scope = this . getScope ( request ) ;
105107 codeChallenge = this . getCodeChallenge ( request , client ) ;
106108
107109 if ( codeChallenge ) {
108110 codeChallengeMethod = this . getCodeChallengeMethod ( request ) ;
109111 }
110112
113+ var requestedScope = this . getScope ( request ) ;
114+
115+ return this . validateScope ( user , client , requestedScope ) ;
116+ } )
117+ . then ( function ( validScope ) {
118+ scope = validScope ;
119+
111120 return this . generateAuthorizationCode ( client , user , scope ) ;
112121 } )
113122 . then ( function ( authorizationCode ) {
@@ -243,6 +252,24 @@ AuthorizeHandler.prototype.getClient = function(request) {
243252 } ) ;
244253} ;
245254
255+ /**
256+ * Validate requested scope.
257+ */
258+ AuthorizeHandler . prototype . validateScope = function ( user , client , scope ) {
259+ if ( this . model . validateScope ) {
260+ return promisify ( this . model . validateScope , 3 ) . call ( this . model , user , client , scope )
261+ . then ( function ( scope ) {
262+ if ( ! scope ) {
263+ throw new InvalidScopeError ( 'Invalid scope: Requested scope is invalid' ) ;
264+ }
265+
266+ return scope ;
267+ } ) ;
268+ } else {
269+ return Promise . resolve ( scope ) ;
270+ }
271+ } ;
272+
246273/**
247274 * Get scope from the request.
248275 */
0 commit comments