Skip to content
Open
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ refs:
- &build
run:
name: Build
command: yarn run build:all
command: yarn run build
- &test
run:
name: Test
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,36 @@ A lot of this code has been copied (with some modificaiton) from the excellent
http://passportjs.org/ project, but I felt it was a shame that all that code was
so locked into the passport framework. My hope is that `@authentication`
provides primatives to allow experimenting with alternative high-level APIs.

<!-- VERSION_TABLE -->
Package Name | Version | Docs
-------------|---------|------
@authentication/cloudflare-ip | [![NPM version](https://img.shields.io/npm/v/@authentication/cloudflare-ip?style=for-the-badge)](https://www.npmjs.com/package/@authentication/cloudflare-ip) | [https://www.atauthentication.com/docs/cloudflare-ip.html](https://www.atauthentication.com/docs/cloudflare-ip.html)
@authentication/cookie | [![NPM version](https://img.shields.io/npm/v/@authentication/cookie?style=for-the-badge)](https://www.npmjs.com/package/@authentication/cookie) | [https://www.atauthentication.com/docs/cookie.html](https://www.atauthentication.com/docs/cookie.html)
@authentication/cookie-session | [![NPM version](https://img.shields.io/npm/v/@authentication/cookie-session?style=for-the-badge)](https://www.npmjs.com/package/@authentication/cookie-session) | [https://www.atauthentication.com/docs/cookie-session.html](https://www.atauthentication.com/docs/cookie-session.html)
@authentication/csrf-protection | [![NPM version](https://img.shields.io/npm/v/@authentication/csrf-protection?style=for-the-badge)](https://www.npmjs.com/package/@authentication/csrf-protection) | [https://www.atauthentication.com/docs/csrf-protection.html](https://www.atauthentication.com/docs/csrf-protection.html)
@authentication/facebook | [![NPM version](https://img.shields.io/npm/v/@authentication/facebook?style=for-the-badge)](https://www.npmjs.com/package/@authentication/facebook) | [https://www.atauthentication.com/docs/facebook.html](https://www.atauthentication.com/docs/facebook.html)
@authentication/generate-passcode | [![NPM version](https://img.shields.io/npm/v/@authentication/generate-passcode?style=for-the-badge)](https://www.npmjs.com/package/@authentication/generate-passcode) | [https://www.atauthentication.com/docs/generate-passcode.html](https://www.atauthentication.com/docs/generate-passcode.html)
@authentication/github | [![NPM version](https://img.shields.io/npm/v/@authentication/github?style=for-the-badge)](https://www.npmjs.com/package/@authentication/github) | [https://www.atauthentication.com/docs/github.html](https://www.atauthentication.com/docs/github.html)
@authentication/google | [![NPM version](https://img.shields.io/npm/v/@authentication/google?style=for-the-badge)](https://www.npmjs.com/package/@authentication/google) | [https://www.atauthentication.com/docs/google.html](https://www.atauthentication.com/docs/google.html)
@authentication/google-authenticator | [![NPM version](https://img.shields.io/npm/v/@authentication/google-authenticator?style=for-the-badge)](https://www.npmjs.com/package/@authentication/google-authenticator) | [https://www.atauthentication.com/docs/google-authenticator.html](https://www.atauthentication.com/docs/google-authenticator.html)
@authentication/passwordless | [![NPM version](https://img.shields.io/npm/v/@authentication/passwordless?style=for-the-badge)](https://www.npmjs.com/package/@authentication/passwordless) | [https://www.atauthentication.com/docs/passwordless.html](https://www.atauthentication.com/docs/passwordless.html)
@authentication/rate-limit | [![NPM version](https://img.shields.io/npm/v/@authentication/rate-limit?style=for-the-badge)](https://www.npmjs.com/package/@authentication/rate-limit) | [https://www.atauthentication.com/docs/rate-limit.html](https://www.atauthentication.com/docs/rate-limit.html)
@authentication/request-url | [![NPM version](https://img.shields.io/npm/v/@authentication/request-url?style=for-the-badge)](https://www.npmjs.com/package/@authentication/request-url) | [https://www.atauthentication.com/docs/request-url.html](https://www.atauthentication.com/docs/request-url.html)
@authentication/secure-hash | [![NPM version](https://img.shields.io/npm/v/@authentication/secure-hash?style=for-the-badge)](https://www.npmjs.com/package/@authentication/secure-hash) | [https://www.atauthentication.com/docs/secure-hash.html](https://www.atauthentication.com/docs/secure-hash.html)
@authentication/send-message | [![NPM version](https://img.shields.io/npm/v/@authentication/send-message?style=for-the-badge)](https://www.npmjs.com/package/@authentication/send-message) | [https://www.atauthentication.com/docs/send-message.html](https://www.atauthentication.com/docs/send-message.html)
@authentication/stripe | [![NPM version](https://img.shields.io/npm/v/@authentication/stripe?style=for-the-badge)](https://www.npmjs.com/package/@authentication/stripe) | [https://www.atauthentication.com/docs/stripe.html](https://www.atauthentication.com/docs/stripe.html)
@authentication/tumblr | [![NPM version](https://img.shields.io/npm/v/@authentication/tumblr?style=for-the-badge)](https://www.npmjs.com/package/@authentication/tumblr) | [https://www.atauthentication.com/docs/tumblr.html](https://www.atauthentication.com/docs/tumblr.html)
@authentication/auth-demo | [![NPM version](https://img.shields.io/npm/v/@authentication/auth-demo?style=for-the-badge)](https://www.npmjs.com/package/@authentication/auth-demo) | Not documented yet
@authentication/base-error | [![NPM version](https://img.shields.io/npm/v/@authentication/base-error?style=for-the-badge)](https://www.npmjs.com/package/@authentication/base-error) | Not documented yet
@authentication/is-email | [![NPM version](https://img.shields.io/npm/v/@authentication/is-email?style=for-the-badge)](https://www.npmjs.com/package/@authentication/is-email) | Not documented yet
@authentication/keygrip | [![NPM version](https://img.shields.io/npm/v/@authentication/keygrip?style=for-the-badge)](https://www.npmjs.com/package/@authentication/keygrip) | Not documented yet
@authentication/lock-by-id | [![NPM version](https://img.shields.io/npm/v/@authentication/lock-by-id?style=for-the-badge)](https://www.npmjs.com/package/@authentication/lock-by-id) | Not documented yet
@authentication/oauth1 | [![NPM version](https://img.shields.io/npm/v/@authentication/oauth1?style=for-the-badge)](https://www.npmjs.com/package/@authentication/oauth1) | Not documented yet
@authentication/oauth2 | [![NPM version](https://img.shields.io/npm/v/@authentication/oauth2?style=for-the-badge)](https://www.npmjs.com/package/@authentication/oauth2) | Not documented yet
@authentication/raw-cookie | [![NPM version](https://img.shields.io/npm/v/@authentication/raw-cookie?style=for-the-badge)](https://www.npmjs.com/package/@authentication/raw-cookie) | Not documented yet
@authentication/react-passwordless | [![NPM version](https://img.shields.io/npm/v/@authentication/react-passwordless?style=for-the-badge)](https://www.npmjs.com/package/@authentication/react-passwordless) | Not documented yet
@authentication/saml-protocol | [![NPM version](https://img.shields.io/npm/v/@authentication/saml-protocol?style=for-the-badge)](https://www.npmjs.com/package/@authentication/saml-protocol) | Not documented yet
@authentication/twitter | [![NPM version](https://img.shields.io/npm/v/@authentication/twitter?style=for-the-badge)](https://www.npmjs.com/package/@authentication/twitter) | Not documented yet
@authentication/types | [![NPM version](https://img.shields.io/npm/v/@authentication/types?style=for-the-badge)](https://www.npmjs.com/package/@authentication/types) | Not documented yet
<!-- VERSION_TABLE -->
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
],
"scripts": {
"postinstall": "node scripts/postinstall",
"build": "node scripts/build-all --only-changed",
"build:all": "node scripts/build-all",
"prerelease": "yarn build:all",
"prettier": "prettier --write \"packages/*/src/**/*.{ts,tsx}\"",
"build": "tsc --build scripts",
"build:watch": "yarn build --watch",
"prerelease": "yarn build",
"prettier:write": "prettier --write \"packages/*/src/**/*.{ts,tsx}\"",
"test": "jest",
"posttest": "wsrun --parallel --exclude-missing test",
"watch:jest": "jest --watch",
Expand Down Expand Up @@ -41,10 +41,10 @@
"jest": "^26.1.0",
"lsr": "^2.0.0",
"mkdirp": "^1.0.4",
"prettier": "^2.0.5",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.1.3",
"typescript": "^3.9.7",
"typescript": "^4.5.5",
"wsrun": "^5.2.1"
},
"resolutions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"start": "moped start"
},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/auth-demo",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/base-error/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "./lib/index.d.ts",
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/base-error",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare-ip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/cloudflare-ip",
"bugs": "https://github.com/ForbesLindesay/authentication/issues",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cookie-session/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/cookie-session",
"bugs": "https://github.com/ForbesLindesay/authentication/issues",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cookie/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/cookie",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/csrf-protection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/csrf-protection",
"bugs": "https://github.com/ForbesLindesay/authentication/issues",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/csrf-protection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {URL} from 'url';

export type ErrorHandler<
TRequest extends IncomingMessage = IncomingMessage,
TResponse extends ServerResponse = ServerResponse
TResponse extends ServerResponse = ServerResponse,
> = (
req: TRequest,
res: TResponse,
Expand All @@ -12,7 +12,7 @@ export type ErrorHandler<
) => any;
export interface Options<
TRequest extends IncomingMessage = IncomingMessage,
TResponse extends ServerResponse = ServerResponse
TResponse extends ServerResponse = ServerResponse,
> {
errorHandler?: ErrorHandler<TRequest, TResponse>;
host?: string;
Expand Down Expand Up @@ -61,7 +61,7 @@ export function getMatcher(host?: string) {
}
export default function csrfProtection<
TRequest extends IncomingMessage = IncomingMessage,
TResponse extends ServerResponse = ServerResponse
TResponse extends ServerResponse = ServerResponse,
>(options: Options<TRequest, TResponse> = {}) {
const ignoreMethods = options.ignoreMethods || ['GET', 'HEAD', 'OPTIONS'];
const matcher = getMatcher(options.host);
Expand Down Expand Up @@ -110,7 +110,7 @@ function getHostFromEnvironment(): undefined | string {
if (typeof baseURL === 'string') {
try {
return new URL(baseURL).host;
} catch (ex) {
} catch (ex: any) {
throw new Error(
`Error parsing ${
process.env.BASE_URL ? 'BASE_URL' : 'BASE_URI'
Expand Down
2 changes: 1 addition & 1 deletion packages/facebook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/facebook",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
14 changes: 6 additions & 8 deletions packages/facebook/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export const DEFAULT_SCOPE: string[] = [];
* Facebook using the OAuth 2.0 protocol.
*/
export default class FacebookAuthentication<State = Mixed>
implements RedirectStrategy<State, InitOptions<State>, CallbackOptions> {
implements RedirectStrategy<State, InitOptions<State>, CallbackOptions>
{
static DEFAULT_SCOPE: ReadonlyArray<string> = DEFAULT_SCOPE;
private readonly _oauth: OAuth2Authentication<State>;
private readonly _clientSecret: string;
Expand Down Expand Up @@ -121,7 +122,7 @@ export default class FacebookAuthentication<State = Mixed>
let body = '';
try {
body = (await this._oauth.get(url, accessToken)).data;
} catch (err) {
} catch (err: any) {
let json: any = null;
if (err.data) {
try {
Expand Down Expand Up @@ -218,7 +219,7 @@ export default class FacebookAuthentication<State = Mixed>
let body = '';
try {
body = (await this._oauth.get(url, accessToken)).data;
} catch (err) {
} catch (err: any) {
let json: any = null;
if (err.data) {
try {
Expand Down Expand Up @@ -285,11 +286,8 @@ export default class FacebookAuthentication<State = Mixed>
);
}

const {
accessToken,
refreshToken,
state,
} = await this._oauth.completeAuthentication(req, res);
const {accessToken, refreshToken, state} =
await this._oauth.completeAuthentication(req, res);
const {profile, rawProfile} = await this.getUserProfile(
accessToken,
options,
Expand Down
4 changes: 0 additions & 4 deletions packages/generate-passcode/Encoding.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/generate-passcode/Encoding.js

This file was deleted.

4 changes: 4 additions & 0 deletions packages/generate-passcode/Encoding/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../lib/Encoding.js",
"types": "../lib/Encoding.d.ts"
}
4 changes: 2 additions & 2 deletions packages/generate-passcode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/generate-passcode",
"bugs": "https://github.com/ForbesLindesay/authentication/issues",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"homepage": "https://www.atauthentication.com/docs/generate-passcode.html"
}
}
2 changes: 0 additions & 2 deletions packages/generate-passcode/src/Encoding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @public

enum Encoding {
base91 = 'base91',
base64 = 'base64',
Expand Down
2 changes: 1 addition & 1 deletion packages/github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/github",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
25 changes: 9 additions & 16 deletions packages/github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const DEFAULT_SCOPE = ['read:user', 'user:email'];
* GitHub using the OAuth 2.0 protocol.
*/
export default class GitHubAuthentication<State = Mixed>
implements RedirectStrategy<State, InitOptions<State>> {
implements RedirectStrategy<State, InitOptions<State>>
{
static DEFAULT_SCOPE: ReadonlyArray<string> = DEFAULT_SCOPE;
private readonly _oauth: OAuth2Authentication<State>;
public readonly callbackPath: string;
Expand Down Expand Up @@ -85,17 +86,15 @@ export default class GitHubAuthentication<State = Mixed>
*
* This function constructs a normalized profile
*/
async getUserProfile(
accessToken: string,
): Promise<{
async getUserProfile(accessToken: string): Promise<{
profile: Profile;
rawProfile: RawGitHubProfile;
rawEmails: null | RawEmail[];
}> {
let body = '';
try {
body = (await this._oauth.get(userProfileURL, accessToken)).data;
} catch (err) {
} catch (err: any) {
let json: any = null;
if (err.data) {
try {
Expand Down Expand Up @@ -125,7 +124,7 @@ export default class GitHubAuthentication<State = Mixed>
let emailsBody = '';
try {
emailsBody = (await this._oauth.get(userEmailsURL, accessToken)).data;
} catch (err) {
} catch (err: any) {
// 404 likely means we just didn't get the user:email OAuth scope
if (err.statusCode !== 404) {
let json: any = null;
Expand Down Expand Up @@ -182,19 +181,13 @@ export default class GitHubAuthentication<State = Mixed>
});
}
async completeAuthenticationWithoutProfile(req: Request, res: Response) {
const {
accessToken,
refreshToken,
state,
} = await this._oauth.completeAuthentication(req, res);
const {accessToken, refreshToken, state} =
await this._oauth.completeAuthentication(req, res);
return {accessToken, refreshToken, state};
}
async completeAuthentication(req: Request, res: Response) {
const {
accessToken,
refreshToken,
state,
} = await this._oauth.completeAuthentication(req, res);
const {accessToken, refreshToken, state} =
await this._oauth.completeAuthentication(req, res);
const {profile, rawProfile, rawEmails} = await this.getUserProfile(
accessToken,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/google-authenticator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/google-authenticator",
"bugs": "https://github.com/ForbesLindesay/authentication/issues",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/google/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/google",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
12 changes: 5 additions & 7 deletions packages/google/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export {GooglePlusAPIError, UserInfoError};
* Google using the OAuth 2.0 protocol.
*/
export default class GoogleAuthentication<State = Mixed>
implements RedirectStrategy<State, InitOptions<State>> {
implements RedirectStrategy<State, InitOptions<State>>
{
static DEFAULT_SCOPE: ReadonlyArray<string> = DEFAULT_SCOPE;
private readonly _oauth: OAuth2Authentication<State>;
public readonly callbackPath: string;
Expand Down Expand Up @@ -143,7 +144,7 @@ export default class GoogleAuthentication<State = Mixed>
let body = '';
try {
body = (await this._oauth.get(userProfileURL, accessToken)).data;
} catch (err) {
} catch (err: any) {
let json: any = null;
if (err.data) {
try {
Expand Down Expand Up @@ -191,11 +192,8 @@ export default class GoogleAuthentication<State = Mixed>
});
}
async completeAuthentication(req: Request, res: Response) {
const {
accessToken,
refreshToken,
state,
} = await this._oauth.completeAuthentication(req, res);
const {accessToken, refreshToken, state} =
await this._oauth.completeAuthentication(req, res);
const {profile} = await this.getUserProfile(accessToken);
return {accessToken, refreshToken, profile, state};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/is-email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/is-email",
"bugs": "https://github.com/ForbesLindesay/authentication/issues",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/keygrip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/keygrip",
"bugs": "https://github.com/ForbesLindesay/authentication/issues",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/lock-by-id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {},
"repository": "https://github.com/ForbesLindesay/authentication/tree/master/packages/lock-by-id",
"bugs": "https://github.com/ForbesLindesay/authentication/issues",
"license": "GPL-3.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
Expand Down
Loading