To use the authorization code grant, you must provide an issue callback to oauth2orize.grant.code(). This callback is responsible for generating the authorization code after a user has approved the request.
The issue Callback Signature
The callback is invoked with the following arguments:
client: The client instance making the authorization request.redirectURI: The redirect URI specified by the client (used as a verifier in the subsequent token exchange).user: The authenticated user approving the request.ares: An object containing additional parameters parsed from the user's decision (e.g., scope, duration of access).done: A callback to issue the code. Signature: done(err, code).
Implementation Example
server.grant(oauth2orize.grant.code(function(client, redirectURI, user, ares, done) {
// Your logic to create and store the authorization code
AuthorizationCode.create(client.id, redirectURI, user.id, ares.scope, function(err, code) {
if (err) { return done(err); }
done(null, code);
});
}));
server.grant(oauth2orize.grant.code(function(client, redirectURI, user, ares, done) {
AuthorizationCode.create(client.id, redirectURI, user.id, ares.scope, function(err, code) {
if (err) { return done(err); }
done(null, code);
});
}));