def register_grant_endpoint(self, server):
        self.app.config.update({'OAUTH2_CODE_CACHE_TYPE': 'simple'})

        def create_access_token(token, client, authorization_code):
            item = Token(client_id=client.client_id,
                         user_id=authorization_code.user_id,
                         **token)
            db.session.add(item)
            db.session.commit()
            # we can add more data into token
            token['user_id'] = authorization_code.user_id

        register_cache_authorization_code(self.app, server,
                                          create_access_token)
    def register_grant(self, server):
        def authenticate_user(authorization_code):
            return User.query.get(authorization_code.user_id)

        cache = SimpleCache()
        register_cache_authorization_code(cache, server, authenticate_user)