all files / express-stormpath/lib/helpers/ revoke-token.js

37.5% Statements 3/8
0% Branches 0/2
0% Functions 0/4
37.5% Lines 3/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                                                                           
'use strict';
 
var requestExecutor = require('../okta/request-executor');
 
/**
 * Revoke a token.
 *
 * @method
 * @private
 *
 * @param {tokenResolverFn} tokenResolver - Function that resolves a token of some kind.
 * @param {string} jwt - Raw JWT.
 * @param {string} jwtSigningKey - Secret used to sign the JWT.
 * @param {callbackFn} callback - Optional callback.
 */
function revokeToken(config, token, tokenType, callback) {
  callback = callback || function () {};
 
  var req = {
    url: config.org + 'oauth2/' + config.authorizationServerId + '/v1/revoke',
    method: 'POST',
    form: {
      token: tokenType,
      token_type_hint: tokenType,
      client_id: config.authorizationServerClientId,
      client_secret: config.authorizationServerClientSecret
    }
  };
 
  requestExecutor(req, callback);
}
 
module.exports = {
  revokeAccessToken: function (config, token, callback) {
    revokeToken(config, token, 'access_token', callback);
  },
  revokeRefreshToken: function (config, token, callback) {
    revokeToken(config, token, 'refresh_token', callback);
  }
};