Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fragment response type and repost view #13

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/ResponseMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ module.exports = {
*/
Query: 'query',

/**
* Authorization Response parameters are encoded in
* the fragment added to the redirect_uri when redirecting back to the Client.
*/
Fragment: 'fragment',

/**
* Authorization Response parameters are encoded as HTML form values
* that are auto-submitted in the User Agent, and thus are transmitted via the HTTP POST method
Expand Down
24 changes: 1 addition & 23 deletions middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ const express = require('express');
const cb = require('cb');
const createError = require('http-errors');
const { get: getConfig } = require('../lib/config');
const memoize = require('p-memoize');
const fs = require('fs');
const { get: getClient } = require('../lib/client');
const requiresAuth = require('./requiresAuth');
const { RequestContext, ResponseContext } = require('../lib/context');

const getRepostView = memoize(() => fs.readFileSync(__dirname + '/../views/repost.html'));

/**
* Returns a router with two routes /login and /callback
*
Expand Down Expand Up @@ -71,7 +67,6 @@ module.exports = function (params) {
}

let callbackMethod;
let repost;

switch (authorizeParams.response_mode) {
case 'form_post':
Expand All @@ -80,18 +75,8 @@ module.exports = function (params) {
case 'query':
callbackMethod = 'get';
break;
case 'fragment':
callbackMethod = 'post';
repost = true;
break;
default:
if (/token/.test(authorizeParams.response_type)) {
callbackMethod = 'post';
repost = true;
}
else {
callbackMethod = 'get';
}
callbackMethod = 'get';
}

router[callbackMethod](config.redirectUriPath, async (req, res, next) => {
Expand Down Expand Up @@ -128,13 +113,6 @@ module.exports = function (params) {
}
});

if (repost) {
router.get('/callback', async (req, res) => {
res.set('Content-Type', 'text/html');
res.send(getRepostView());
});
}

if (config.required) {
const requiresAuthMiddleware = requiresAuth();
if (typeof config.required === 'function') {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions test/auth.tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const assert = require('chai').assert;
const url = require('url');
const fs = require('fs');
const request = require('request-promise-native').defaults({
simple: false,
resolveWithFullResponse: true
Expand Down Expand Up @@ -184,19 +183,9 @@ describe('auth', function() {
});

it('should contain the two callbacks route', function() {
assert.ok(router.stack.some(filterRoute('POST', '/callback')));
assert.ok(router.stack.some(filterRoute('GET', '/callback')));
});

it('should return an html on GET /callback', async function() {
const cookieJar = request.jar();
const res = await request.get('/callback', { cookieJar, baseUrl, followRedirect: false });
assert.equal(res.statusCode, 200);
assert.equal(res.headers['content-type'], 'text/html; charset=utf-8');
const expectedBody = fs.readFileSync(`${__dirname}/../views/repost.html`, 'utf-8');
assert.equal(res.body, expectedBody);
});

});
});
});
52 changes: 0 additions & 52 deletions test/respot.tests.js

This file was deleted.

42 changes: 0 additions & 42 deletions views/repost.html

This file was deleted.