Skip to content

Commit

Permalink
Merge pull request #25 from financialforcedev/feature/generic-oauth-p…
Browse files Browse the repository at this point in the history
…rovider-updates

Feature/generic oauth provider updates
  • Loading branch information
Steve Fry committed Mar 12, 2019
2 parents 30e0a13 + 169c05a commit 1d33272
Show file tree
Hide file tree
Showing 73 changed files with 8,049 additions and 3,123 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -3,7 +3,7 @@ coverage
dist
node_modules

config/local*
**/config/local*

*.cert
*.key
Expand Down
16 changes: 0 additions & 16 deletions certificates/serverCertificateGenerator.txt

This file was deleted.

19 changes: 19 additions & 0 deletions config/default.json
@@ -0,0 +1,19 @@
{
"authProvider": {
"google": {
"httpTimeout": 4000,
"issuerURI": "https://accounts.google.com",
"type": "OpenID"
},
"salesforceConnection": {
"httpTimeout": 4000,
"issuerURI": "https://test.salesforce.com",
"type": "Salesforce"
},
"salesforceIdentity": {
"httpTimeout": 4000,
"issuerURI": "https://test.salesforce.com",
"type": "Salesforce"
}
}
}
2 changes: 2 additions & 0 deletions examples/.gitignore
@@ -0,0 +1,2 @@
node_modules
dist
1 change: 1 addition & 0 deletions examples/.npmrc
@@ -0,0 +1 @@
package-lock=false
18 changes: 18 additions & 0 deletions examples/.vscode/launch.json
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug App",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"src/index.ts"
],
"console": "integratedTerminal"
}
]
}
10 changes: 10 additions & 0 deletions examples/.vscode/settings.json
@@ -0,0 +1,10 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
},
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.insertSpaces": false,
"files.insertFinalNewline": true
}
23 changes: 23 additions & 0 deletions examples/config/default.json
@@ -0,0 +1,23 @@
{
"app": {
"authProvider": {
"salesforce": {
"httpTimeout": 4000,
"issuerURI": "https://test.salesforce.com",
"type": "Salesforce"
}
},
"openid": {
"salesforce": {
"immediate": false,
"prompt": "consent",
"redirectUri": "https://localhost:8080/api/auth/v1.0/callback",
"scope": "openid",
"verifySignature": false
},
"salesforceConnection": {
"scope": "api"
}
}
}
}
38 changes: 38 additions & 0 deletions examples/package.json
@@ -0,0 +1,38 @@
{
"name": "orizuru-auth-examples",
"version": "1.0.0",
"description": "Orizuru Auth Examples",
"main": "dist/index.js",
"files": [
"src"
],
"repository": {
"type": "git",
"url": "https://github.com/financialforcedev/orizuru-auth"
},
"scripts": {
"build": "rm -rf dist && tsc",
"build-clean": "rm -rf dist",
"build-compile": "tsc",
"install-dependencies": "npm i",
"start": "npm run install-dependencies && npm run build && node dist/index.js"
},
"author": "FinancialForce",
"license": "BSD-3-Clause",
"dependencies": {
"@financialforcedev/orizuru": "^9.3.0",
"@financialforcedev/orizuru-auth": "^7.0.0",
"@financialforcedev/orizuru-transport-rabbitmq": "^5.0.1",
"@types/config": "0.0.34",
"@types/jsforce": "^1.9.5",
"@types/pem": "^1.9.5",
"config": "^3.0.1",
"jsforce": "^1.9.1",
"pem": "^1.14.2"
},
"devDependencies": {
"ts-node": "^8.0.3",
"tslint": "^5.13.1",
"typescript": "^3.3.3333"
}
}
72 changes: 72 additions & 0 deletions examples/src/index.ts
@@ -0,0 +1,72 @@
// Imports
import { json, Request, Response, Server } from '@financialforcedev/orizuru';
import { flow } from '@financialforcedev/orizuru-auth';
import { Transport } from '@financialforcedev/orizuru-transport-rabbitmq';
import config from 'config';
import https from 'https';
import pem, { CertificateCreationResult } from 'pem';

// Define a function that creates a self-signed certificate
function createCertificate(): Promise<CertificateCreationResult> {
return new Promise((resolve, reject) => {
pem.createCertificate({ days: 1, selfSigned: true }, (err, result) => {
if (err) {
return reject(err);
}

process.stdout.write('Created certificate\n');
return resolve(result);
});
});
}

// Create the server
const server = new Server({
authProvider: {
salesforce: config.get('app.authProvider.salesforce')
},
openid: {
salesforce: config.get('app.openid.salesforce'),
salesforceConnection: config.get('app.openid.salesforceConnection')
},
port: 8080,
transport: new Transport({
prefetch: 1,
url: 'amqp://localhost'
})
});

// Add the route to generate the authorization URL (in this case we use 'test' as the state parameter)
server.addRoute({
method: 'get',
middleware: [
json()
],
responseWriter: () => async (err: Error | undefined, req: Request, res: Response) => {
const url = await flow.webServer.authorizationUrlGenerator(server.options.authProvider.salesforce)(server.options.openid.salesforce, server.options.openid.salesforce);
res.redirect(url);
},
schema: {
fields: [],
name: 'auth',
namespace: 'api.v1_0',
type: 'record'
},
synchronous: true
});

// **All code specified in the rest of the readme should be added here**

// Create a self-signed certificate and then start the server listening to connections using HTTPS
createCertificate().then((certificate) => {

const serverOptions: https.ServerOptions = {
cert: certificate.certificate,
key: certificate.clientKey
};

const httpsServer = https.createServer(serverOptions, server.serverImpl);
httpsServer.listen(server.options.port);
process.stdout.write('Started server\n');

});
22 changes: 22 additions & 0 deletions examples/tsconfig.json
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"declaration": true,
"declarationDir": "dist/types",
"esModuleInterop": true,
"inlineSourceMap": true,
"inlineSources": true,
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "./dist",
"strict": true,
"strictNullChecks": true,
"target": "es2017"
},
"include": [
"src"
]
}
25 changes: 25 additions & 0 deletions examples/tslint.json
@@ -0,0 +1,25 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"rules": {
"indent": [
true,
"tabs",
4
],
"max-line-length": false,
"quotemark": [
true,
"single"
],
"trailing-comma": [
true,
{
"multiline": "never",
"singleline": "never"
}
]
}
}

0 comments on commit 1d33272

Please sign in to comment.