@feathersjs/authentication-oauth
Version:
oAuth 1 and 2 authentication for Feathers. Powered by Grant.
46 lines • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.oauth = exports.OAuthService = exports.OAuthStrategy = void 0;
const commons_1 = require("@feathersjs/commons");
const schema_1 = require("@feathersjs/schema");
const strategy_1 = require("./strategy");
Object.defineProperty(exports, "OAuthStrategy", { enumerable: true, get: function () { return strategy_1.OAuthStrategy; } });
const service_1 = require("./service");
Object.defineProperty(exports, "OAuthService", { enumerable: true, get: function () { return service_1.OAuthService; } });
const utils_1 = require("./utils");
const debug = (0, commons_1.createDebug)('@feathersjs/authentication-oauth');
const oauth = (settings = {}) => (app) => {
const authService = app.defaultAuthentication ? app.defaultAuthentication(settings.authService) : null;
if (!authService) {
throw new Error('An authentication service must exist before registering @feathersjs/authentication-oauth');
}
if (!authService.configuration.oauth) {
debug('No oauth configuration found in authentication configuration. Skipping oAuth setup.');
return;
}
const oauthOptions = {
linkStrategy: 'jwt',
...settings
};
const grantConfig = (0, utils_1.getGrantConfig)(authService);
const serviceOptions = (0, utils_1.authenticationServiceOptions)(authService, oauthOptions);
const servicePath = `${grantConfig.defaults.prefix || 'oauth'}/:provider`;
const callbackServicePath = `${servicePath}/callback`;
const oauthService = new service_1.OAuthService(authService, oauthOptions);
app.use(servicePath, oauthService, serviceOptions);
app.use(callbackServicePath, new service_1.OAuthCallbackService(oauthService), serviceOptions);
app.service(servicePath).hooks({
around: { all: [(0, schema_1.resolveDispatch)(), (0, service_1.redirectHook)()] }
});
app.service(callbackServicePath).hooks({
around: { all: [(0, schema_1.resolveDispatch)(), (0, service_1.redirectHook)()] }
});
if (typeof app.service(servicePath).publish === 'function') {
app.service(servicePath).publish(() => null);
}
if (typeof app.service(callbackServicePath).publish === 'function') {
app.service(callbackServicePath).publish(() => null);
}
};
exports.oauth = oauth;
//# sourceMappingURL=index.js.map