问题
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