   authorization: ->
     [
       ensureLogin.ensureLoggedIn()
-      @server.authorization (clientId, redirectURI, done)=> @findClient clientId, redirectURI, done
-      @renderFunction
+      @server.authorization (clientId, redirectURI, done)=>
+        @findClient clientId, redirectURI, done
+
+      if typeof @autoApprove is 'function' then @autoApprove.bind(this) else passby
+      @renderFunction.bind(this)
     ]
 
   decision: ->


passport = null


class Provider

  @uid = util.uid

  defaultRenderFunction = (req, res)->
    res.render('dialog', { transactionID: req.oauth2.transactionID, user: req.user, client: req.oauth2.client })

  constructor: (config, deps)->
    ## normalize parameters
    throw new Error 'Your argument is invalid: need config object' unless config?
    @renderFunction = config.renderFunction or defaultRenderFunction


    @passport = passport = deps.passport
    throw new Error 'passport instance must be provided' unless passport

      ## init oauth server
    @server = oauth2orize.createServer()

    ## register serialize/deserialize functions (easier for inheritance)

      @server.errorHandler()
    ]

module.exports = Provider
