Skip to content

Commit

Permalink
ADAPT-4167: Extract Auth SDK into standalone project (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Plowman authored Feb 8, 2022
1 parent 33bfb4f commit 0a784f1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 35 deletions.
2 changes: 0 additions & 2 deletions index.ts

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"name": "adapt-auth-sdk",
"version": "1.0.0-dev",
"description": "Provides all the functionality needed to easily integrate your Javascript web applications with Stanford SAML federated identity provider.",
"main": "dist/bundle.js",
"main": "dist/index.js",
"types": "dist/types.d.ts",
"files": [
"dist/bundle.js"
"dist"
],
"scripts": {
"build": "webpack",
"build": "tsc",
"prepare": "npm run build",
"lint": "eslint \"src/**/*.{ts,tsx.js,jsx}\"",
"lint:fix": "eslint \"src/**/*.{ts,tsx,js,jsx}\" --quiet --fix",
Expand Down
20 changes: 15 additions & 5 deletions src/AdaptAuth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
import { Handler, Response, NextFunction } from 'express';
import passport from 'passport';
import * as passport from 'passport';
import { Strategy as SamlStrategy } from 'passport-saml';
import jwt from 'jsonwebtoken';
import * as jwt from 'jsonwebtoken';
import { serialize } from 'cookie';
import {
AdaptAuthConfig,
Expand Down Expand Up @@ -62,7 +62,6 @@ export class AdaptAuth {
encodedSUID: profile.encodedSUID as string,
};

// Attach relayState to req
try {
(req as SamlUserRequest).samlRelayState = JSON.parse(req.body.RelayState);
} catch (err) {
Expand Down Expand Up @@ -191,7 +190,7 @@ export class AdaptAuth {

// Response
return this.createSession()(req as SamlUserRequest, res, () => {
const loginRedirect = redirectUrl || this.config.session.loginRedirectUrl;
const loginRedirect = redirectUrl || this.getFinalDestination(req) || this.config.session.loginRedirectUrl;
if (loginRedirect) {
res.redirect(loginRedirect);
} else {
Expand Down Expand Up @@ -241,7 +240,18 @@ export class AdaptAuth {
/**
* Helper to extract the saml relay final destination url from req object
*/
public getFinalDestination = (req: any) => ((req as SamlUserRequest).samlRelayState || {}).finalDestination;
public getFinalDestination = (req: any) => {
// Attach relayState to req
try {
const relayState = req.samlRelayState;
const finalDest = relayState.finalDestination || null;
return finalDest;

} catch (err) {
// I guess the relayState wasn't that great...
console.log('Unable to parse samlRelayState', err);
}
};
}

// Singleton client for default consumption
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './AdaptAuth';
export * from './types';
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"compilerOptions": {
"outDir": "./dist/",
"module": "es6",
"outDir": "./dist",
"module": "commonjs",
"declaration": true,
"target": "es5",
"allowJs": true,
"moduleResolution": "node"
},
"include": ["src"],
"exclude": ["node_modules"]
}
23 changes: 0 additions & 23 deletions webpack.config.js

This file was deleted.

0 comments on commit 0a784f1

Please sign in to comment.