What is the user in this node.js package code?

强颜欢笑 提交于 2019-12-25 07:34:12

问题


I am studying the client-oauth2 npm package. The code sample from the link in the preceding sentence includes the word user. What does user refer to? Is user a built in type? Or does the developer need to create their own user model class? If so, please give a good example of how to create and integrate a user model class. Any links to documentation about user or code samples for user for this package would also be greatly appreciated.

Here is a code snipped from the link above which includes the word user:

app.get('/auth/github/callback', function (req, res) {
  githubAuth.code.getToken(req.url)
    .then(function (user) {
      console.log(user) //=> { accessToken: '...', tokenType: 'bearer', ... } 

      // Refresh the current users access token. 
      user.refresh().then(function (updatedUser) {
        console.log(updatedUser === user) //=> true 
      })

      // Sign API requests on behalf of the current user. 
      user.sign({
        method: 'get',
        url: 'http://example.com'
      })

      // We should store the token into a database. 
      return res.send(user.accessToken)
    })
}

The following methods and properties seem to be required of a user object:

user.refresh()  
user.sign({method: 'get',  
    url: 'http://example.com'})    
user.accessToken  

It seems obvious that user.accessToken stores the user's OAuth2 access token in memory. But what specifically do the refresh() and sign(...) methods do? And what code should be used to implement them, if they are not built-in types?

来源:https://stackoverflow.com/questions/38162115/what-is-the-user-in-this-node-js-package-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!