├── test3 ├── .gitignore ├── gitignore.backup ├── awsLambdaTest ├── event.json ├── index.js └── readme.md ├── awsCloudformationRunLambda ├── .DS_Store ├── runOnce.zip ├── index.js ├── customResourceRunLambda.yaml ├── deploy.sh ├── readme.md └── cfn-response.js ├── oktaMultipleLoginPage ├── images │ └── pony.png ├── index.html └── readme.md ├── gitignore └── readme.md ├── amazonDeleteS3Buckets └── readme.md ├── awsLambdaStock └── readme.md ├── amazonDeleteCloudLogs └── readme.md ├── amazonLambdaMisc └── readme.md ├── awsSam2 ├── src │ └── index.js ├── deploy.sh ├── template.yaml ├── readme.md └── output.yaml ├── awsS3DeleteBucketsWithVersioning └── readme.md ├── awsSam ├── HelloWorld │ └── lambda_function.py ├── 01-basic-sam-template.yaml ├── TestAuthorizerFunc │ └── lambda_function.py ├── deploy.sh ├── 02-sam-swagger-tamplate.yaml ├── 03-sam-swagger-auth-template.yaml └── readme.md ├── oktaKeystore └── readme.md ├── awsSamOktaRental ├── bookings │ └── index.js ├── deploy.sh ├── readme.md ├── template.yaml └── vehicles │ └── index.js ├── awsOktaRentalWithAuthorizer ├── bookings │ └── index.js ├── authorizer │ └── authorizer.js ├── deploy.sh ├── readme.md ├── template.yaml └── vehicles │ └── index.js ├── awsCloudformationMakeBucket ├── readme.md ├── template.yml ├── deploy.sh └── setups3bucket │ ├── cfn-response.js │ ├── index.js │ └── oktaLoginPage.html ├── starterHTML └── readme.md ├── amazonS3CommonCommands └── readme.md ├── securityCertificatesCreate └── readme.md ├── dockerNginxHacking └── readme.md ├── amazonLambdaUpload └── readme.md ├── dockerSnapshot └── readme.md ├── awsAnythingGoesAuthorizer ├── denyAnything.js ├── allowAnything.js └── readme.md ├── angularNotes └── readme.md ├── awsLaunchStack ├── launchstack.yaml └── readme.md ├── awsCustomResourceOutput └── readme.md ├── awsSamOktaGuest ├── deploy.sh ├── output.yaml ├── template.yaml ├── src │ └── index.js └── readme.md ├── lambdaEdgeStaticWebpage └── readme.md ├── phpDecodeJwt └── readme.md ├── awsCloudformationInlineLambdaWithRole └── readme.md ├── loginWidgetCorsOnPhp └── readme.md ├── oktaServer ├── Dockerfile └── readme.md ├── nodeRandomSnippets └── readme.md ├── javascriptPromises └── readme.md ├── awsCloudformationCustomResourceOrchestration └── readme.md ├── lambdaEdgeSetCookie └── readme.md ├── loginWidgetJsfiddle └── readme.md ├── readme.md └── loginWidgetBootstrap ├── index.html └── readme.md /test3: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | node_modules/* 3 | bin/* 4 | pkg/* 5 | src/github.com/* 6 | 7 | -------------------------------------------------------------------------------- /gitignore.backup: -------------------------------------------------------------------------------- 1 | .idea/* 2 | node_modules/* 3 | bin/* 4 | pkg/* 5 | src/github.com/* 6 | 7 | -------------------------------------------------------------------------------- /awsLambdaTest/event.json: -------------------------------------------------------------------------------- 1 | { 2 | "key3": "value3", 3 | "key2": "value2", 4 | "key1": "value1" 5 | } 6 | 7 | -------------------------------------------------------------------------------- /awsCloudformationRunLambda/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmcdowell-okta/my-notes/HEAD/awsCloudformationRunLambda/.DS_Store -------------------------------------------------------------------------------- /oktaMultipleLoginPage/images/pony.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmcdowell-okta/my-notes/HEAD/oktaMultipleLoginPage/images/pony.png -------------------------------------------------------------------------------- /awsCloudformationRunLambda/runOnce.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmcdowell-okta/my-notes/HEAD/awsCloudformationRunLambda/runOnce.zip -------------------------------------------------------------------------------- /awsLambdaTest/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | // TODO implement 3 | callback(null, 'Hello from Lambda'); 4 | }; 5 | 6 | -------------------------------------------------------------------------------- /gitignore/readme.md: -------------------------------------------------------------------------------- 1 | ### Git Ignore 2 | 3 | This is the code I use to prevent get from fetching my .idea and other files. 4 | 5 | ``` 6 | .idea/* 7 | node_modules/* 8 | bin/* 9 | pkg/* 10 | src/github.com/* 11 | ``` 12 | 13 | 14 | -------------------------------------------------------------------------------- /amazonDeleteS3Buckets/readme.md: -------------------------------------------------------------------------------- 1 | ### Delete all S3 Buckets 2 | 3 | *Use at your own Risk*, this has saved me a lot of time during testing. Clear out your S3 Buckets. 4 | 5 | ``` 6 | aws s3 ls | cut -d" " -f 3 | xargs -I{} aws s3 rb s3://{} --force 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /awsLambdaStock/readme.md: -------------------------------------------------------------------------------- 1 | ### Stock Lambda Function in AWS 2 | 3 | nothing special here, this is the beginning of a Lambda Function in AWS 4 | 5 | ``` 6 | exports.handler = (event, context, callback) => { 7 | // TODO implement 8 | callback(null, 'Hello from Lambda'); 9 | }; 10 | ``` 11 | 12 | -------------------------------------------------------------------------------- /amazonDeleteCloudLogs/readme.md: -------------------------------------------------------------------------------- 1 | ## Delete all Cloud Logs 2 | 3 | This is super helpful when you are debugging. 4 | 5 | ``` 6 | aws logs describe-log-groups --query 'logGroups[*].logGroupName' --output table | awk '{print $2}' | grep -v ^$ | while read x; do aws logs delete-log-group --log-group-name $x; done 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /amazonLambdaMisc/readme.md: -------------------------------------------------------------------------------- 1 | ### Misc other commands I use when working with Lambdas 2 | 3 | list functions: 4 | `aws lambda list-functions` 5 | 6 | list functions, just names: 7 | `aws lambda list-functions | grep -i functionName` 8 | 9 | delete functions: 10 | `aws lambda delete-function --function-name TryCallBack` 11 | -------------------------------------------------------------------------------- /awsCloudformationRunLambda/index.js: -------------------------------------------------------------------------------- 1 | var response = require('cfn-response'); 2 | 3 | exports.handler = (event, context, callback) => { 4 | // TODO implement 5 | 6 | console.log("runOnceRan!"); 7 | 8 | //callback(null, 'Hello from Lambda'); 9 | 10 | response.send(event, context, response.SUCCESS, {"1":"2"}); 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /awsSam2/src/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | // TODO implement 3 | 4 | var response = { 5 | statusCode: 200, 6 | body: JSON.stringify("Cool you got response"), 7 | "isBase64Encoded": false 8 | }; 9 | console.log("response: " + JSON.stringify(response)) 10 | callback(null, response); 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /awsS3DeleteBucketsWithVersioning/readme.md: -------------------------------------------------------------------------------- 1 | ### Deleting buckets with Versioning is a HASTLE.. 2 | 3 | This script worked for me.. Thx who ever posted in 4 | 5 | ``` 6 | import boto3 7 | 8 | BUCKET = 'elasticbeanstalk-us-west-2-761861444952' 9 | 10 | s3 = boto3.resource('s3') 11 | bucket = s3.Bucket(BUCKET) 12 | bucket.object_versions.delete() 13 | ``` 14 | 15 | 16 | -------------------------------------------------------------------------------- /awsSam/HelloWorld/lambda_function.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | 4 | def lambda_handler(event, context): 5 | return response('Hello World!', 200) 6 | 7 | 8 | def response(message, status_code): 9 | return { 10 | 'isBase64Encoded': False, 11 | 'statusCode': status_code, 12 | 'body': json.dumps(message), 13 | 'headers': {'Content-Type': 'application/json'} 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /awsCloudformationRunLambda/customResourceRunLambda.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: Can you make a Lambda Function run 4 | 5 | 6 | Resources: 7 | test: 8 | Type: Custom::test 9 | Properties: 10 | ServiceToken: arn:aws:lambda:us-east-1:761861444952:function:runOnce 11 | # Input: some input 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /oktaKeystore/readme.md: -------------------------------------------------------------------------------- 1 | ### Okta Keystore for On Premise Agents. 2 | 3 | If you are working with Okta On Premise Agent, and using HTTPS, you need to add the Okta Key to the JRE's keystore (or vice a versa), but this is the command you will need to do that. 4 | 5 | Only took 3 hours for me to figure that out. 6 | 7 | `keytool -keystore cacerts -import -alias localhost -file /okta/server.crt` 8 | 9 | Add key to On Prem provisioning JRE 10 | 11 | -------------------------------------------------------------------------------- /awsSamOktaRental/bookings/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | 3 | var bookings= { 4 | "vehicle_id":"733-23-13", 5 | "estimated_cost":"$ 120.00 USD", 6 | "confirmation_code":"HEUWIDWHDJIWY" 7 | } 8 | 9 | var response = { 10 | statusCode: 200, 11 | body: JSON.stringify(bookings), 12 | "isBase64Encoded": false 13 | }; 14 | console.log("response: " + JSON.stringify(response)) 15 | callback(null, response); 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /awsOktaRentalWithAuthorizer/bookings/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | 3 | var bookings= { 4 | "vehicle_id":"733-23-13", 5 | "estimated_cost":"$ 120.00 USD", 6 | "confirmation_code":"HEUWIDWHDJIWY" 7 | } 8 | 9 | var response = { 10 | statusCode: 200, 11 | body: JSON.stringify(bookings), 12 | "isBase64Encoded": false 13 | }; 14 | console.log("response: " + JSON.stringify(response)) 15 | callback(null, response); 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/readme.md: -------------------------------------------------------------------------------- 1 | ### Cloudformation template that creates S3 Bucket with login widget 2 | 3 | This project creates an S3 Bucket, then puts the HTML for an 4 | Okta Login widget on it. And when deleted, removes everything. 5 | 6 | #### To run it from the command line 7 | 8 | `./deploy.sh oktacoder77 makebucket24 template.yml --parameter-overrides oktaOrg=companyx.okta.com bucketname=saturday8834` 9 | 10 | #### To Delete the Stack 11 | `aws cloudformation delete-stack --stack-name makebucket23` -------------------------------------------------------------------------------- /awsSam/01-basic-sam-template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: An example serverless "Hello World" application. 4 | 5 | Resources: 6 | HelloWorld: 7 | Type: AWS::Serverless::Function 8 | Properties: 9 | Handler: lambda_function.lambda_handler 10 | Runtime: python3.6 11 | CodeUri: ./HelloWorld 12 | Events: 13 | GetApi: 14 | Type: Api 15 | Properties: 16 | Path: / 17 | Method: get 18 | -------------------------------------------------------------------------------- /starterHTML/readme.md: -------------------------------------------------------------------------------- 1 | #### Convenient to have some simple HTML with javascript ready to run, this is what I often start with. Similar to what you get with JSFiddle. 2 | 3 | 4 | 5 | ``` 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 |

hi2

18 |

hi

19 | 20 | 21 | 22 | 23 | ``` 24 | -------------------------------------------------------------------------------- /amazonS3CommonCommands/readme.md: -------------------------------------------------------------------------------- 1 | ### Common Commands you should know when working with S3 2 | 3 | #### Make bucket 4 | `aws s3 mb s3://123demo123` 5 | 6 | #### List buckets 7 | `aws s3 ls` 8 | 9 | #### Copy files 10 | `aws s3 cp . s3://bucketname` 11 | 12 | #### Delete S3 Bucket 13 | `aws s3 rb "s3://authorizer8-dev-serverlessdeploymentbucket-16pc0b9h3515g" --force` 14 | 15 | #### S3 Sync 16 | `aws s3 sync . s3://my-bucket/path` 17 | 18 | #### Delete multiple buckets 19 | `for kk in $(aws s3 ls | grep -i golang | cut -f3 -d ' '); do $(aws s3 rb s3://$kk --force) ;done` 20 | -------------------------------------------------------------------------------- /securityCertificatesCreate/readme.md: -------------------------------------------------------------------------------- 1 | #### Make Certificates super fast 2 | 3 | ``` 4 | #!/usr/bin/env bash 5 | case `uname -s` in 6 | Linux*) sslConfig=/etc/ssl/openssl.cnf;; 7 | Darwin*) sslConfig=/System/Library/OpenSSL/openssl.cnf;; 8 | esac 9 | openssl req \ 10 | -newkey rsa:2048 \ 11 | -x509 \ 12 | -nodes \ 13 | -keyout server.key \ 14 | -new \ 15 | -out server.pem \ 16 | -subj /CN=localhost \ 17 | -reqexts SAN \ 18 | -extensions SAN \ 19 | -config <(cat $sslConfig \ 20 | <(printf '[SAN]\nsubjectAltName=DNS:localhost')) \ 21 | -sha256 \ 22 | -days 3650 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /dockerNginxHacking/readme.md: -------------------------------------------------------------------------------- 1 | #### Hacking Nginx as reverse proxy 2 | 3 | ##### Create a local file called nginx.conf 4 | 5 | Add this: 6 | 7 | ``` 8 | events { 9 | worker_connections 1024; 10 | } 11 | 12 | http { 13 | server { 14 | listen 8000; 15 | server_name localhost; 16 | location / { 17 | proxy_pass http://oktaproxy.com; 18 | } 19 | } 20 | } 21 | ``` 22 | 23 | ##### Run Docker with this command: 24 | 25 | ``` 26 | docker run -it -p 80:8000 -v "$PWD":/etc/nginx nginx /bin/bash -c "nginx ; bash" 27 | ``` 28 | ##### Then Connect to `http://localhost:80` 29 | 30 | You should see Oktaproxy running on your local machine 31 | 32 | 33 | -------------------------------------------------------------------------------- /amazonLambdaUpload/readme.md: -------------------------------------------------------------------------------- 1 | ### Upload Lambda function to AWS 2 | 3 | Assuming you have the CLI installed and setup: 4 | 5 | ``` 6 | aws lambda create-function \ 7 | --region us-east-1 \ 8 | --function-name deletemeNOW \ 9 | --zip-file fileb://./file.zip \ 10 | --runtime go1.x \ 11 | --tracing-config Mode=Active \ 12 | --role arn:aws:iam::761861444952:role/wef_lambda_function \ 13 | --handler index 14 | 15 | NODE Version 16 | 17 | aws lambda create-function --region us-east-1 --function-name deletemeNOW --zip-file fileb://./file.zip --runtime nodejs4.3 --tracing-config Mode=Active --role arn:aws:iam::761861444952:role/wef_lambda_function --handler index.handler 18 | ``` 19 | 20 | -------------------------------------------------------------------------------- /awsLambdaTest/readme.md: -------------------------------------------------------------------------------- 1 | ### Testing Lambdas locally 2 | 3 | #### Uploading and testing lambdas is a pain. 4 | 5 | I am using lambda-local https://www.npmjs.com/package/lambda-local 6 | 7 | **Install it like this:** `npm install -g lambda-local` 8 | 9 | They have examples on their website, but here is a basic one that works, 10 | it is based on the stock lambda that Amazon Creates for you 11 | 12 | `lambda-local -l index.js -h handler -e event.json` 13 | 14 | when it's done, if you copy my source, you will see this: 15 | 16 | ``` 17 | info: START RequestId: 9f9f5113-b335-d115-4aa8-06e08ab63e89 18 | info: End - Message 19 | info: ------ 20 | info: Hello from Lambda 21 | info: ------ 22 | info: Lambda successfully executed in 7ms. 23 | ``` 24 | -------------------------------------------------------------------------------- /dockerSnapshot/readme.md: -------------------------------------------------------------------------------- 1 | ### How to take a snapshot in Docker 2 | 3 | Once you have your Docker Image setup, and you want to SnapShot it. 4 | 5 | Press **CTRL + P**, then **CTRL+Q** 6 | 7 | Then run: 8 | 9 | `docker ps` 10 | 11 | This will show you the Container ID that is running. 12 | 13 | Then run: 14 | 15 | `docker commit 451d643f8dd0 mybackup` 16 | 17 | To restart your images run: 18 | 19 | `docker run –it mybackup bash` 20 | 21 | If you want to attach your console to an image that is running, you can use 22 | 23 | `docker attach 451d643f8dd0` <-This is the ID of the running container 24 | 25 | For example, you can reattach to your running image after you snapshot 26 | 27 | To start up your snapshot again, at any time just run it like so 28 | 29 | `docker run –it mybackup bash` 30 | 31 | -------------------------------------------------------------------------------- /awsAnythingGoesAuthorizer/denyAnything.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const generatePolicy = function(principalId, effect, resource) { 4 | const authResponse = {}; 5 | authResponse.principalId = principalId; 6 | if (effect && resource) { 7 | const policyDocument = {}; 8 | policyDocument.Version = '2012-10-17'; 9 | policyDocument.Statement = []; 10 | const statementOne = {}; 11 | statementOne.Action = 'execute-api:Invoke'; 12 | statementOne.Effect = effect; 13 | statementOne.Resource = resource; 14 | policyDocument.Statement[0] = statementOne; 15 | authResponse.policyDocument = policyDocument; 16 | } 17 | return authResponse; 18 | }; 19 | 20 | module.exports.authorizer = (event, context, callback) => { 21 | 22 | callback(null, generatePolicy('user123', 'Deny', event.methodArn)); 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /awsAnythingGoesAuthorizer/allowAnything.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const generatePolicy = function(principalId, effect, resource) { 4 | const authResponse = {}; 5 | authResponse.principalId = principalId; 6 | if (effect && resource) { 7 | const policyDocument = {}; 8 | policyDocument.Version = '2012-10-17'; 9 | policyDocument.Statement = []; 10 | const statementOne = {}; 11 | statementOne.Action = 'execute-api:Invoke'; 12 | statementOne.Effect = effect; 13 | statementOne.Resource = resource; 14 | policyDocument.Statement[0] = statementOne; 15 | authResponse.policyDocument = policyDocument; 16 | } 17 | return authResponse; 18 | }; 19 | 20 | module.exports.authorizer = (event, context, callback) => { 21 | 22 | callback(null, generatePolicy('user123', 'Allow', event.methodArn)); 23 | 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /awsSam/TestAuthorizerFunc/lambda_function.py: -------------------------------------------------------------------------------- 1 | def generate_policy(principal_id, effect=None, resource=None): 2 | auth_response = { 3 | 'principalId': principal_id 4 | } 5 | 6 | if effect and resource: 7 | auth_response['policyDocument'] = { 8 | 'Version': '2012-10-17', 9 | 'Statement': [ 10 | { 11 | 'Action': 'execute-api:Invoke', 12 | 'Effect': effect, 13 | 'Resource': resource 14 | } 15 | ] 16 | } 17 | 18 | return auth_response 19 | 20 | 21 | 22 | 23 | def lambda_handler(event, context): 24 | token = event['authorizationToken'] 25 | method_arn = event['methodArn'] 26 | print(f"Client token: {token}") 27 | print(f"Method ARN: {method_arn}") 28 | 29 | if token == 'Bearer a.b.c': 30 | return generate_policy(token, 'Allow', method_arn) 31 | else: 32 | raise Exception('Unauthorized') 33 | -------------------------------------------------------------------------------- /awsSam/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | S3_BUCKET=$1 4 | STACK_NAME=$2 5 | 6 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME" 7 | 8 | if [ -z "$S3_BUCKET" ]; then 9 | echo "Missing S3_BUCKET and STACK_NAME" 10 | echo $USE_MSG 11 | exit 1 12 | fi 13 | 14 | if [ -z "$STACK_NAME" ]; then 15 | echo "Missing STACK_NAME" 16 | echo $USE_MSG 17 | exit 1 18 | fi 19 | 20 | # zip up functionZZ 21 | #zip api-proxy-lambda.zip index.js 22 | 23 | # upload zip to S3 24 | sam package --template-file 03-sam-swagger-auth-template.yaml --s3-bucket $S3_BUCKET --output-template-file output.yaml 25 | 26 | # deploy to cloud formation 27 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM 28 | 29 | # get API endpoint 30 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 31 | 32 | # remove quotes 33 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 34 | 35 | echo "Test in browser: $API_ENDPOINT" 36 | 37 | 38 | -------------------------------------------------------------------------------- /angularNotes/readme.md: -------------------------------------------------------------------------------- 1 | ### Angular notes 2 | 3 | **Start New Project**
4 | ` 5 | ng new ng5 --style=scss --routing 6 | ` 7 | 8 | **Serve Pages on port 4200**
9 | ``` 10 | ng serve 11 | ``` 12 | 13 | **Build**
14 | This is the command you will run to build the app for static server
15 | ` 16 | ng build 17 | ` 18 | 19 | **Make components** 20 | 21 | ``` 22 | ng g c home 23 | ng g c about 24 | ng g c page-not-found -it -is 25 | (Inline template and inline styles) 26 | ``` 27 | 28 | **Routing:** 29 | 30 | Edit: `` 31 | app.routing.module.ts 32 | `` 33 | **example:** 34 | 35 | ``` 36 | const routes: Routes = [ 37 | { path: '', redirectTo: '/home', pathMatch : 'full' }, 38 | { path: 'home', component : HomeComponent }, 39 | { path: 'about', component : AboutComponent }, 40 | { path: 'about/:id', component : AboutComponent }, //Pass Parameter 41 | { path: '**', component : PageNotFoundComponent }, 42 | 43 | ]; 44 | ``` 45 | 46 | **ngOnInit** 47 | Invoked first time when initialized 48 | 49 | 50 | -------------------------------------------------------------------------------- /awsOktaRentalWithAuthorizer/authorizer/authorizer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const generatePolicy = function(principalId, effect, resource) { 4 | const authResponse = {}; 5 | authResponse.principalId = principalId; 6 | if (effect && resource) { 7 | const policyDocument = {}; 8 | policyDocument.Version = '2012-10-17'; 9 | policyDocument.Statement = []; 10 | const statementOne = {}; 11 | statementOne.Action = 'execute-api:Invoke'; 12 | statementOne.Effect = effect; 13 | statementOne.Resource = resource; 14 | policyDocument.Statement[0] = statementOne; 15 | authResponse.policyDocument = policyDocument; 16 | } 17 | return authResponse; 18 | }; 19 | 20 | exports.authorizer = (event, context, callback) => { 21 | 22 | console.log("Hit Authorizer") 23 | 24 | 25 | //Toggle the callback for Opposite day ! 26 | callback(null, generatePolicy('user123', 'Deny', event.methodArn)); 27 | // callback(null, generatePolicy('user123', 'Allow', event.methodArn)); 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /awsLaunchStack/launchstack.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Description: Template for the S3 static website 3 | Resources: 4 | S3Bucket: 5 | Type: AWS::S3::Bucket 6 | Properties: 7 | AccessControl: PublicRead 8 | WebsiteConfiguration: 9 | IndexDocument: index.html 10 | DeletionPolicy: Retain 11 | S3WebsiteBucketPolicy: 12 | Type: AWS::S3::BucketPolicy 13 | Properties: 14 | Bucket: !Ref S3Bucket 15 | PolicyDocument: 16 | Statement: 17 | - 18 | Action: 19 | - "s3:GetObject" 20 | Effect: "Allow" 21 | Resource: !Sub "arn:aws:s3:::${S3Bucket}/*" 22 | Principal: "*" 23 | Outputs: 24 | BucketName: 25 | Value: !Ref S3Bucket 26 | Description: The created bucket name 27 | WebsiteURL: 28 | Value: !GetAtt S3Bucket.WebsiteURL 29 | Description: URL for the website hosted on S3 30 | S3BucketSecureURL: 31 | Value: !Sub 32 | - https://${Domain} 33 | - Domain: !GetAtt S3Bucket.DomainName 34 | Description: Name of the S3 bucket to hold website content 35 | 36 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/template.yml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: newmakebucket 4 | Parameters: 5 | Environment: 6 | Type: String 7 | Default: dev 8 | StageName: 9 | Type: String 10 | Default: prod 11 | Description: Testing new makebucket 12 | oktaOrg: 13 | Type: String 14 | Description: Name of Okta Org 15 | bucketname: 16 | Type: String 17 | Description: name of bucket 18 | 19 | Resources: 20 | creates3bucketlambda: 21 | Type: AWS::Serverless::Function 22 | Properties: 23 | Handler: index.handler 24 | Runtime: nodejs6.10 25 | CodeUri: setups3bucket 26 | MemorySize: 512 27 | Timeout: 300 28 | Policies: 29 | - AWSLambdaBasicExecutionRole 30 | - AmazonDynamoDBFullAccess 31 | - AmazonS3FullAccess 32 | 33 | DeploymentCustomResource: 34 | Type: Custom::AppConfiguration 35 | Properties: 36 | ServiceToken: !GetAtt creates3bucketlambda.Arn 37 | oktaOrg: 38 | !Ref oktaOrg 39 | bucketname: 40 | !Ref bucketname 41 | 42 | -------------------------------------------------------------------------------- /awsAnythingGoesAuthorizer/readme.md: -------------------------------------------------------------------------------- 1 | #### Anything goes AWS Authorizer 2 | 3 | I know this seems silly to have an Authorizer that allows 4 | anything, but when experimenting with SAM or Serverless 5 | Framework, it makes it easier to test the configuration 6 | with a Authorizer that will always permit/deny 7 | 8 | ``` 9 | 'use strict'; 10 | 11 | const generatePolicy = function(principalId, effect, resource) { 12 | const authResponse = {}; 13 | authResponse.principalId = principalId; 14 | if (effect && resource) { 15 | const policyDocument = {}; 16 | policyDocument.Version = '2012-10-17'; 17 | policyDocument.Statement = []; 18 | const statementOne = {}; 19 | statementOne.Action = 'execute-api:Invoke'; 20 | statementOne.Effect = effect; 21 | statementOne.Resource = resource; 22 | policyDocument.Statement[0] = statementOne; 23 | authResponse.policyDocument = policyDocument; 24 | } 25 | return authResponse; 26 | }; 27 | 28 | module.exports.authorizer = (event, context, callback) => { 29 | 30 | callback(null, generatePolicy('user123', 'Allow', event.methodArn)); 31 | 32 | }; 33 | ``` -------------------------------------------------------------------------------- /awsCustomResourceOutput/readme.md: -------------------------------------------------------------------------------- 1 | #### Capturing output from a custom resource 2 | 3 | Sometimes you want to display the output from a Lambda Custom 4 | Resource, this worked for me. 5 | 6 | In the Template: 7 | 8 | #### template.yaml 9 | 10 | ``` 11 | AWSTemplateFormatVersion: 2010-09-09 12 | Transform: AWS::Serverless-2016-10-31 13 | Description: Can you make a Lambda Function run 14 | 15 | Outputs: 16 | NameOfOurVariable: 17 | Value: 18 | Fn::GetAtt: 19 | - test 20 | - key 21 | # The resource is called test, the value we are getting is called key 22 | # The value is called key, Key is what we are looking for 23 | 24 | Resources: 25 | test: 26 | Type: Custom::test 27 | Properties: 28 | ServiceToken: arn:aws:lambda:us-east-1:761861444952:function:runOnce 29 | ``` 30 | 31 | #### index.js 32 | 33 | My Lambda Function 34 | 35 | ``` 36 | var response = require('cfn-response'); 37 | 38 | exports.handler = (event, context, callback) => { 39 | // TODO implement 40 | 41 | console.log("runOnceRan!"); 42 | 43 | response.send(event, context, response.SUCCESS, {"key":"value"}); 44 | }; 45 | ``` -------------------------------------------------------------------------------- /awsSam/02-sam-swagger-tamplate.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: An example serverless "Hello World" application. 4 | 5 | Resources: 6 | ApiGateway: 7 | Type: AWS::Serverless::Api 8 | Properties: 9 | StageName: Prod 10 | DefinitionBody: 11 | swagger: 2.0 12 | info: 13 | title: 14 | Ref: AWS::StackName 15 | paths: 16 | "/": 17 | get: 18 | x-amazon-apigateway-integration: 19 | httpMethod: post 20 | type: aws_proxy 21 | uri: 22 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloWorld.Arn}/invocations 23 | responses: {} 24 | 25 | HelloWorld: 26 | Type: AWS::Serverless::Function 27 | Properties: 28 | Handler: lambda_function.lambda_handler 29 | Runtime: python3.6 30 | CodeUri: ./HelloWorld 31 | Events: 32 | GetApi: 33 | Type: Api 34 | Properties: 35 | Path: / 36 | Method: get 37 | RestApiId: 38 | Ref: ApiGateway 39 | -------------------------------------------------------------------------------- /awsSam2/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | S3_BUCKET=$1 4 | STACK_NAME=$2 5 | TEMPLATE_FILE=$3 6 | 7 | #rm output.yaml 8 | #aws cloudformation delete-stack --stack-name swagger03 9 | 10 | 11 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME" 12 | 13 | if [ -z "$S3_BUCKET" ]; then 14 | echo "Missing S3_BUCKET and STACK_NAME" 15 | echo $USE_MSG 16 | exit 1 17 | fi 18 | 19 | if [ -z "$STACK_NAME" ]; then 20 | echo "Missing STACK_NAME" 21 | echo $USE_MSG 22 | exit 1 23 | fi 24 | 25 | if [ -z "$TEMPLATE_FILE" ]; then 26 | echo "Missing TEMPLATE_FILE" 27 | echo $USE_MSG 28 | exit 1 29 | fi 30 | 31 | # upload to S3 32 | sam package --template-file $TEMPLATE_FILE --s3-bucket $S3_BUCKET --output-template-file output.yaml 33 | 34 | # deploy to cloud formation 35 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM 36 | 37 | # get API endpoint 38 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 39 | 40 | # remove quotes 41 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 42 | 43 | echo "" 44 | echo "Test in browser: $API_ENDPOINT" 45 | 46 | echo "" 47 | echo "To Delete the Stack use this command" 48 | echo "aws cloudformation delete-stack --stack-name $STACK_NAME" 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /awsSamOktaGuest/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | S3_BUCKET=$1 4 | STACK_NAME=$2 5 | TEMPLATE_FILE=$3 6 | 7 | #rm output.yaml 8 | #aws cloudformation delete-stack --stack-name swagger03 9 | 10 | 11 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME" 12 | 13 | if [ -z "$S3_BUCKET" ]; then 14 | echo "Missing S3_BUCKET and STACK_NAME" 15 | echo $USE_MSG 16 | exit 1 17 | fi 18 | 19 | if [ -z "$STACK_NAME" ]; then 20 | echo "Missing STACK_NAME" 21 | echo $USE_MSG 22 | exit 1 23 | fi 24 | 25 | if [ -z "$TEMPLATE_FILE" ]; then 26 | echo "Missing TEMPLATE_FILE" 27 | echo $USE_MSG 28 | exit 1 29 | fi 30 | 31 | # upload to S3 32 | sam package --template-file $TEMPLATE_FILE --s3-bucket $S3_BUCKET --output-template-file output.yaml 33 | 34 | # deploy to cloud formation 35 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM 36 | 37 | # get API endpoint 38 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 39 | 40 | # remove quotes 41 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 42 | 43 | echo "" 44 | echo "Test in browser: $API_ENDPOINT" 45 | 46 | echo "" 47 | echo "To Delete the Stack use this command" 48 | echo "aws cloudformation delete-stack --stack-name $STACK_NAME" 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /awsCloudformationRunLambda/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | S3_BUCKET=$1 4 | STACK_NAME=$2 5 | TEMPLATE_FILE=$3 6 | 7 | #rm output.yaml 8 | #aws cloudformation delete-stack --stack-name swagger03 9 | 10 | 11 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME" 12 | 13 | if [ -z "$S3_BUCKET" ]; then 14 | echo "Missing S3_BUCKET and STACK_NAME" 15 | echo $USE_MSG 16 | exit 1 17 | fi 18 | 19 | if [ -z "$STACK_NAME" ]; then 20 | echo "Missing STACK_NAME" 21 | echo $USE_MSG 22 | exit 1 23 | fi 24 | 25 | if [ -z "$TEMPLATE_FILE" ]; then 26 | echo "Missing TEMPLATE_FILE" 27 | echo $USE_MSG 28 | exit 1 29 | fi 30 | 31 | # upload to S3 32 | sam package --template-file $TEMPLATE_FILE --s3-bucket $S3_BUCKET --output-template-file output.yaml 33 | 34 | # deploy to cloud formation 35 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM 36 | 37 | # get API endpoint 38 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 39 | 40 | # remove quotes 41 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 42 | 43 | echo "" 44 | echo "Test in browser: $API_ENDPOINT" 45 | 46 | echo "" 47 | echo "To Delete the Stack use this command" 48 | echo "aws cloudformation delete-stack --stack-name $STACK_NAME" 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /lambdaEdgeStaticWebpage/readme.md: -------------------------------------------------------------------------------- 1 | ### Static web page on Lambda Edge 2 | 3 | I used this code to get familiar with Lambda Edge, this just renders a static webpage. 4 | 5 | Ideally, you would most likely use a S3 Bucket, but this got me started. 6 | 7 | ``` 8 | 'use strict'; 9 | 10 | let content = ` 11 | <\!DOCTYPE html> 12 | 13 | 14 | 15 | Simple Lambda@Edge Static Content Response 16 | 17 | 18 |

Hello from Lambda@Edge!

19 | 20 | 21 | `; 22 | 23 | exports.handler = (event, context, callback) => { 24 | /* 25 | * Generate HTTP OK response using 200 status code with HTML body. 26 | */ 27 | const response = { 28 | status: '200', 29 | statusDescription: 'OK', 30 | headers: { 31 | 'cache-control': [{ 32 | key: 'Cache-Control', 33 | value: 'max-age=100' 34 | }], 35 | 'content-type': [{ 36 | key: 'Content-Type', 37 | value: 'text/html' 38 | }], 39 | 'content-encoding': [{ 40 | key: 'Content-Encoding', 41 | value: 'UTF-8' 42 | }], 43 | }, 44 | body: content, 45 | }; 46 | callback(null, response); 47 | }; 48 | 49 | ``` 50 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | S3_BUCKET=$1 4 | STACK_NAME=$2 5 | TEMPLATE_FILE=$3 6 | 7 | #rm output.yaml 8 | #aws cloudformation delete-stack --stack-name swagger03 9 | 10 | 11 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME" 12 | 13 | if [ -z "$S3_BUCKET" ]; then 14 | echo "Missing S3_BUCKET and STACK_NAME" 15 | echo $USE_MSG 16 | exit 1 17 | fi 18 | 19 | if [ -z "$STACK_NAME" ]; then 20 | echo "Missing STACK_NAME" 21 | echo $USE_MSG 22 | exit 1 23 | fi 24 | 25 | if [ -z "$TEMPLATE_FILE" ]; then 26 | echo "Missing TEMPLATE_FILE" 27 | echo $USE_MSG 28 | exit 1 29 | fi 30 | 31 | # upload to S3 32 | sam package --template-file $TEMPLATE_FILE --s3-bucket $S3_BUCKET --output-template-file output.yaml 33 | 34 | # deploy to cloud formation 35 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM $4 $5 $6 $7 36 | 37 | # get API endpoint 38 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 39 | 40 | # remove quotes 41 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 42 | 43 | echo "" 44 | echo "Test in browser: $API_ENDPOINT" 45 | 46 | echo "" 47 | echo "To Delete the Stack use this command" 48 | echo "aws cloudformation delete-stack --stack-name $STACK_NAME &" 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /phpDecodeJwt/readme.md: -------------------------------------------------------------------------------- 1 | ## Poor mans JWT decode.. (Not Verify) 2 | 3 | This is the code I use to decode a JWT from 64encoded to object in PHP 4 | 5 | ``` 6 | Middle Segment !"; 13 | 14 | echo $tokenSegments[1]; echo "

"; 15 | 16 | $tokenDecoded= base64_decode($tokenSegments[1]); 17 | 18 | echo "JSON !

"; 19 | echo $tokenDecoded; 20 | 21 | $tokenObject = json_decode($tokenDecoded); 22 | 23 | echo "

Object !

"; 24 | echo $tokenObject->preferred_username; 25 | 26 | ?> 27 | 28 | ``` 29 | -------------------------------------------------------------------------------- /awsCloudformationRunLambda/readme.md: -------------------------------------------------------------------------------- 1 | ### Run a Lambda function or whatever with Custom Resource 2 | 3 | This was hard for me to figure out, and I'm still processing 4 | what I got to work, but this sample code might help you invoke 5 | a Lambda Function or what ever you want with a **Custom Resource**. 6 | 7 | All the source is included, and the deploy.sh script I used to 8 | push it out. 9 | 10 | ##### index.js 11 | 12 | The lambda function just console.logs some output, and returns 13 | success, that was all I wanted to prove. 14 | 15 | ``` 16 | var response = require('cfn-response'); 17 | exports.handler = (event, context, callback) => { 18 | console.log("runOnceRan!"); 19 | response.send(event, context, response.SUCCESS, {"1":"2"}); 20 | }; 21 | 22 | ``` 23 | 24 | You need to include cfn-response.js in the lambda. For some 25 | reason long to explain it is not provided by AWS. 26 | 27 | ##### customResourceRunLambda.yaml 28 | 29 | The cloudformation template just calls this Lambda function 30 | 31 | ``` 32 | AWSTemplateFormatVersion: 2010-09-09 33 | Transform: AWS::Serverless-2016-10-31 34 | Description: Can you make a Lambda Function run 35 | 36 | Resources: 37 | test: 38 | Type: Custom::test 39 | Properties: 40 | ServiceToken: arn:aws:lambda:us-east-1:761861444952:function:runOnce 41 | # OptionalParamater : "OptionalParamaeterPassed" 42 | ``` 43 | 44 | #### Optional Parameters are passed to Lambda like this: 45 | 46 | ``` 47 | // From event, so event.ResourceProperties.key1 would be the value 48 | 49 | ResourceProperties: 50 | { key1: 'theKeyYouPassed', 51 | ``` -------------------------------------------------------------------------------- /awsSamOktaGuest/output.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Description: Okta Guest Login 3 | Outputs: 4 | ExampleAPIUrl: 5 | Value: 6 | Fn::Sub: https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/ 7 | Parameters: 8 | Environment: 9 | Default: dev 10 | Description: Create a Lambda Function that will login Okta Guest 11 | Type: String 12 | Resources: 13 | HelloAPI: 14 | Properties: 15 | DefinitionBody: 16 | info: 17 | title: 18 | Ref: AWS::StackName 19 | paths: 20 | /guest: 21 | get: 22 | responses: {} 23 | x-amazon-apigateway-integration: 24 | httpMethod: POST 25 | type: aws_proxy 26 | uri: 27 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${OktaGuestLogin.Arn}/invocations 28 | swagger: 2.0 29 | StageName: 30 | Fn::Sub: ${Environment} 31 | Type: AWS::Serverless::Api 32 | OktaGuestLogin: 33 | Properties: 34 | CodeUri: s3://okta911/dfd26e1e50faa033e61eae43b6ea59e3 35 | Events: 36 | MyEndpoint: 37 | Properties: 38 | Method: GET 39 | Path: /guest 40 | RestApiId: 41 | Ref: HelloAPI 42 | Type: Api 43 | Handler: index.handler 44 | MemorySize: 128 45 | Policies: 46 | - AWSLambdaBasicExecutionRole 47 | - AmazonDynamoDBFullAccess 48 | Runtime: nodejs4.3 49 | Timeout: 30 50 | Type: AWS::Serverless::Function 51 | Transform: AWS::Serverless-2016-10-31 52 | -------------------------------------------------------------------------------- /awsSamOktaGuest/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: Okta Guest Login 4 | Parameters: 5 | Environment: 6 | Type: String 7 | Default: dev 8 | Description: Create a Lambda Function that will login Okta Guest 9 | 10 | Outputs: 11 | ExampleAPIUrl: 12 | Value: !Sub "https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/" 13 | 14 | Resources: 15 | HelloAPI: 16 | Type: AWS::Serverless::Api 17 | Properties: 18 | StageName: !Sub ${Environment} 19 | DefinitionBody: 20 | swagger: 2.0 21 | info: 22 | title: 23 | Ref: AWS::StackName 24 | paths: 25 | /guest: 26 | get: 27 | x-amazon-apigateway-integration: 28 | httpMethod: POST 29 | type: aws_proxy 30 | uri: 31 | !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${OktaGuestLogin.Arn}/invocations 32 | responses: {} 33 | OktaGuestLogin: 34 | Type: AWS::Serverless::Function 35 | Properties: 36 | # FunctionName: !Sub HelloLambda-${Environment} 37 | Handler: index.handler 38 | Runtime: nodejs4.3 39 | CodeUri: src 40 | MemorySize: 128 41 | Timeout: 30 42 | Policies: 43 | - AWSLambdaBasicExecutionRole 44 | - AmazonDynamoDBFullAccess 45 | Events: 46 | MyEndpoint: 47 | Type: Api 48 | Properties: 49 | Path: /guest 50 | Method: GET 51 | RestApiId: 52 | Ref: HelloAPI 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /awsCloudformationInlineLambdaWithRole/readme.md: -------------------------------------------------------------------------------- 1 | #### Create in-line Lambda with Role 2 | 3 | This will not change the world, but it will help you create 4 | an inline Lambda Function in a Cloudformation tempalte. 5 | 6 | Creates and assigns role too. 7 | 8 | ``` 9 | AWSTemplateFormatVersion: 2010-09-09 10 | Transform: AWS::Serverless-2016-10-31 11 | Description: inline Lambda 12 | 13 | Resources: 14 | LambdaExecutionRole: 15 | Type: AWS::IAM::Role 16 | Properties: 17 | AssumeRolePolicyDocument: 18 | Version: '2012-10-17' 19 | Statement: 20 | - Effect: Allow 21 | Principal: {Service: [lambda.amazonaws.com]} 22 | Action: ['sts:AssumeRole'] 23 | Path: / 24 | ManagedPolicyArns: 25 | - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole 26 | Policies: 27 | - PolicyName: PublishVersion 28 | PolicyDocument: 29 | Version: 2012-10-17 30 | Statement: 31 | - Effect: Allow 32 | Action: ['lambda:PublishVersion'] 33 | Resource: '*' 34 | 35 | inlineLambdaDeleteMe: 36 | Type: AWS::Lambda::Function 37 | Properties: 38 | Code: 39 | ZipFile: !Sub | 40 | var aws = require('aws-sdk'); 41 | exports.handler = function(event, context) { 42 | console.log ("In Lambda Function"); 43 | var data={}; 44 | data.key="value" 45 | context.succeed(JSON.stringify(data)); 46 | }; 47 | Handler: index.handler 48 | Runtime: nodejs6.10 49 | Timeout: '30' 50 | Role: !GetAtt LambdaExecutionRole.Arn 51 | 52 | 53 | 54 | 55 | ``` -------------------------------------------------------------------------------- /awsSam2/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: AWS SAM Tutorial 4 | Parameters: 5 | Environment: 6 | Type: String 7 | Default: dev 8 | StageName: 9 | Type: String 10 | Default: prod 11 | Description: The Lambda Function and API Gateway Stage 12 | 13 | Outputs: 14 | ExampleAPIUrl: 15 | Value: !Sub "https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/" 16 | 17 | Resources: 18 | HelloAPI: 19 | Type: AWS::Serverless::Api 20 | Properties: 21 | StageName: !Sub ${Environment} 22 | DefinitionBody: 23 | swagger: 2.0 24 | info: 25 | title: 26 | Ref: AWS::StackName 27 | paths: 28 | /test: 29 | get: 30 | x-amazon-apigateway-integration: 31 | httpMethod: POST 32 | type: aws_proxy 33 | uri: 34 | !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambda.Arn}/invocations 35 | responses: {} 36 | HelloLambda: 37 | Type: AWS::Serverless::Function 38 | Properties: 39 | FunctionName: !Sub HelloLambda-${Environment} 40 | Handler: index.handler 41 | Runtime: nodejs4.3 42 | CodeUri: src 43 | MemorySize: 128 44 | Timeout: 30 45 | Policies: 46 | - AWSLambdaBasicExecutionRole 47 | - AmazonDynamoDBFullAccess 48 | Events: 49 | MyEndpoint: 50 | Type: Api 51 | Properties: 52 | Path: /test 53 | Method: GET 54 | RestApiId: 55 | Ref: HelloAPI 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /awsSam2/readme.md: -------------------------------------------------------------------------------- 1 | ## SAM / Cloudformation 2 | 3 | It takes a while to get a feel for working with SAM. This is another 4 | example of a simple Lambda function sitting behind an API Gateway. 5 | 6 | I tried to make a simple deployment script based on work done Chenr2, and others to make it easier to understand. 7 | 8 | Hopefully it will help others, and I hope to add an Authorizer to this simple example. 9 | 10 | ### To Deploy do this 11 | 12 | `./deploy.sh YOURS3BUCKETNAME YOURSTACKNAME template.yaml` 13 | 14 | ##### If you forget how to create an S3 bucket do this: 15 | `aws s3 mb s3://YOURBUCKETNAME` 16 | 17 | If everything works as it should, you will see a response like this: 18 | 19 | ``` 20 | Waiting for changeset to be created.. 21 | Waiting for stack create/update to complete 22 | Successfully created/updated stack - chenr2r2 23 | 24 | Test in browser: https://zv27pqu5x9.execute-api.us-east-1.amazonaws.com/dev/ 25 | 26 | To Delete the Stack use this command 27 | aws cloudformation delete-stack --stack-name YOURSTACKNAME 28 | ``` 29 | ### Test 30 | 31 | You can test with curl like this `curl https://zv27pqu5x9.execute-api.us-east-1.amazonaws.com/dev/test` 32 | 33 | the response should look like this: 34 | ``` 35 | "Cool you got response" 36 | ``` 37 | 38 | The Lambda function, is pretty much a stock Lambda function for the API Gateway 39 | 40 | ``` 41 | exports.handler = (event, context, callback) => { 42 | // TODO implement 43 | 44 | var response = { 45 | statusCode: 200, 46 | body: JSON.stringify("Cool you got response"), 47 | "isBase64Encoded": false 48 | }; 49 | console.log("response: " + JSON.stringify(response)) 50 | callback(null, response); 51 | }; 52 | 53 | 54 | ``` -------------------------------------------------------------------------------- /awsSamOktaRental/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | S3_BUCKET=$1 4 | STACK_NAME=$2 5 | TEMPLATE_FILE=$3 6 | 7 | #rm output.yaml 8 | #aws cloudformation delete-stack --stack-name swagger03 9 | 10 | 11 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME YOURSAMTEMPLATE.YAML" 12 | 13 | if [ -z "$S3_BUCKET" ]; then 14 | echo "Missing S3_BUCKET and STACK_NAME, if you forgot how to create a S3 bucket, here is the command:" 15 | echo "aws s3 mb s3://YOURBUCKETNAME" 16 | echo $USE_MSG 17 | exit 1 18 | fi 19 | 20 | if [ -z "$STACK_NAME" ]; then 21 | echo "Missing STACK_NAME, this is needed to name your cloudformation stack" 22 | echo $USE_MSG 23 | exit 1 24 | fi 25 | 26 | if [ -z "$TEMPLATE_FILE" ]; then 27 | echo "Missing TEMPLATE_FILE, we need your SAM Template file" 28 | echo $USE_MSG 29 | exit 1 30 | fi 31 | 32 | # upload to S3 33 | sam package --template-file $TEMPLATE_FILE --s3-bucket $S3_BUCKET --output-template-file output.yaml 34 | 35 | # deploy to cloud formation 36 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM 37 | 38 | # get API endpoint 39 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 40 | 41 | # remove quotes 42 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 43 | 44 | rm output.yaml 45 | 46 | echo "" 47 | echo "Test in browser: $API_ENDPOINT" 48 | 49 | echo "Vehicles API" 50 | echo "Test in browser: $API_ENDPOINT""vehicles" 51 | 52 | echo "Bookings API" 53 | echo "Test in browser: $API_ENDPOINT""bookings" 54 | 55 | 56 | echo "" 57 | echo "To Delete the Stack use this command" 58 | echo "aws cloudformation delete-stack --stack-name $STACK_NAME" 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /loginWidgetCorsOnPhp/readme.md: -------------------------------------------------------------------------------- 1 | ## This is what you want to run if you want to accept CORS from any location on a PHP Server 2 | 3 | ``` 4 | 33 | 34 | ``` 35 | ## This is what you want to run on your Javascript if you want to pass a Bearer Token 36 | 37 | ``` 38 | 39 | 40 | $.ajax({ 41 | url: 'http://localhost', 42 | headers: { 43 | 'Authorization': `Bearer efefefefefefef`, 44 | }, 45 | method: 'POST', 46 | data: "", 47 | success: function(data){ 48 | console.log('succes: '+data); 49 | } 50 | }); 51 | 52 | /* $.post( "http://localhost", 53 | 54 | function( data ) { 55 | console.log ( data ) 56 | }); */ 57 | 58 | // find elements 59 | var banner = $("#banner-message") 60 | var button = $("button") 61 | 62 | // handle click and add class 63 | button.on("click", function(){ 64 | banner.addClass("alt") 65 | }) 66 | 67 | 68 | 69 | ``` 70 | -------------------------------------------------------------------------------- /oktaServer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM centos:7 2 | ENV container docker 3 | ENV GOPATH /root 4 | 5 | 6 | RUN printf " _ _ \n ___ | |__| |_ __ _ \n / _ \| / /| _|/ _\` |\n \___/|_\_\ \__|\__,_\n" 7 | 8 | 9 | RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in ; do [ $i == \ 10 | systemd-tmpfiles-setup.service ] || rm -f $i; done); \ 11 | rm -f /lib/systemd/system/multi-user.target.wants/;\ 12 | rm -f /etc/systemd/system/.wants/;\ 13 | rm -f /lib/systemd/system/local-fs.target.wants/; \ 14 | rm -f /lib/systemd/system/sockets.target.wants/udev; \ 15 | rm -f /lib/systemd/system/sockets.target.wants/initctl; \ 16 | rm -f /lib/systemd/system/basic.target.wants/;\ 17 | rm -f /lib/systemd/system/anaconda.target.wants/*; 18 | 19 | 20 | #RUN mkdir /okta 21 | ADD https://companyx-admin.okta.com/static/agents/ProvisioningAgent/OktaProvisioningAgent-01.01.00.x86_64.rpm / 22 | ADD https://raw.githubusercontent.com/pmcdowell-okta/golangOktaScimServer/master/goLangScimServer.linux / 23 | RUN chmod 777 /goLangScimServer.linux 24 | RUN chmod +x /goLangScimServer.linux 25 | RUN yum update -y 26 | RUN yum clean all 27 | 28 | 29 | #Don't need JDK, but just incase anyone still uses Java 30 | RUN yum install -y java-1.7.0-openjdk 31 | 32 | 33 | RUN yum install -y wget curl nc git golang 34 | RUN echo Download Gorilla Stuff 35 | RUN go get github.com/gorilla/mux 36 | RUN go get github.com/gorilla/sessions 37 | 38 | 39 | RUN git clone https://github.com/pmcdowell-okta/golangOktaScimServer.git 40 | 41 | 42 | #installing wget, curl, and netCat for testing ! 43 | 44 | 45 | RUN yum -y install initscripts 46 | 47 | 48 | #this makes the service commands work in CentOs 49 | 50 | 51 | VOLUME [ "/sys/fs/cgroup" ] 52 | CMD ["/usr/sbin/init"] 53 | 54 | -------------------------------------------------------------------------------- /awsOktaRentalWithAuthorizer/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | S3_BUCKET=$1 4 | STACK_NAME=$2 5 | TEMPLATE_FILE=$3 6 | 7 | #rm output.yaml 8 | #aws cloudformation delete-stack --stack-name swagger03 9 | 10 | 11 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME YOURSAMTEMPLATE.YAML" 12 | 13 | if [ -z "$S3_BUCKET" ]; then 14 | echo "Missing S3_BUCKET and STACK_NAME, if you forgot how to create a S3 bucket, here is the command:" 15 | echo "aws s3 mb s3://YOURBUCKETNAME" 16 | echo $USE_MSG 17 | exit 1 18 | fi 19 | 20 | if [ -z "$STACK_NAME" ]; then 21 | echo "Missing STACK_NAME, this is needed to name your cloudformation stack" 22 | echo $USE_MSG 23 | exit 1 24 | fi 25 | 26 | if [ -z "$TEMPLATE_FILE" ]; then 27 | echo "Missing TEMPLATE_FILE, we need your SAM Template file" 28 | echo $USE_MSG 29 | exit 1 30 | fi 31 | 32 | # upload to S3 33 | sam package --template-file $TEMPLATE_FILE --s3-bucket $S3_BUCKET --output-template-file output.yaml 34 | 35 | # deploy to cloud formation 36 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM 37 | 38 | # get API endpoint 39 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 40 | 41 | # remove quotes 42 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 43 | 44 | rm output.yaml 45 | 46 | echo "" 47 | echo "Test in browser: $API_ENDPOINT" 48 | 49 | echo "Vehicles API" 50 | echo "Test in browser: $API_ENDPOINT""vehicles" 51 | 52 | echo "Bookings API" 53 | echo "Test in browser: $API_ENDPOINT""bookings" 54 | 55 | 56 | echo "" 57 | echo "To Delete the Stack use this command" 58 | echo "aws cloudformation delete-stack --stack-name $STACK_NAME" 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /awsSam2/output.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Description: AWS SAM Tutorial 3 | Outputs: 4 | ExampleAPIUrl: 5 | Value: 6 | Fn::Sub: https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/ 7 | Parameters: 8 | Environment: 9 | Default: dev 10 | Type: String 11 | StageName: 12 | Default: prod 13 | Description: The Lambda Function and API Gateway Stage 14 | Type: String 15 | Resources: 16 | HelloAPI: 17 | Properties: 18 | DefinitionBody: 19 | info: 20 | title: 21 | Ref: AWS::StackName 22 | paths: 23 | /test: 24 | get: 25 | responses: {} 26 | x-amazon-apigateway-integration: 27 | httpMethod: POST 28 | type: aws_proxy 29 | uri: 30 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambda.Arn}/invocations 31 | swagger: 2.0 32 | StageName: 33 | Fn::Sub: ${Environment} 34 | Type: AWS::Serverless::Api 35 | HelloLambda: 36 | Properties: 37 | CodeUri: s3://okta911/cf4b2ea3e8e6a0df2da8ec41e6a10711 38 | Events: 39 | MyEndpoint: 40 | Properties: 41 | Method: GET 42 | Path: /test 43 | RestApiId: 44 | Ref: HelloAPI 45 | Type: Api 46 | FunctionName: 47 | Fn::Sub: HelloLambda-${Environment} 48 | Handler: index.handler 49 | MemorySize: 128 50 | Policies: 51 | - AWSLambdaBasicExecutionRole 52 | - AmazonDynamoDBFullAccess 53 | Runtime: nodejs4.3 54 | Timeout: 30 55 | Type: AWS::Serverless::Function 56 | Transform: AWS::Serverless-2016-10-31 57 | -------------------------------------------------------------------------------- /nodeRandomSnippets/readme.md: -------------------------------------------------------------------------------- 1 | ### My Random Node Snippets 2 | 3 | *Doubt many will find this useful except for me* 4 | 5 | ##### Readfile 6 | `fs.readFile("fragment.html", function(err, fragment) {` 7 | 8 | ##### search replace string all occurances 9 | `var temp = fragmentOriginal.replace(/{{tag}}/g, val.title)` 10 | 11 | ##### for loop object elements 12 | ``` 13 | for (var key in requestObj.requestAttributes) { 14 | if (requestObj.requestAttributes.hasOwnProperty(key)) { 15 | var val = requestObj.requestAttributes[key]; 16 | // console.log(JSON.stringify(val)); 17 | requestObj.html +="

"+val.title+"


" 18 | } 19 | } 20 | ``` 21 | 22 | ##### Quick web server 23 | ``` 24 | var http = require('http'); 25 | var url = require('url'); 26 | 27 | http.createServer(function (req, res) { 28 | res.writeHead(200, {'Content-Type': 'text/html'}); 29 | var q = url.parse(req.url, true).query; 30 | var txt = q.year + " " + q.month; 31 | if (req.url == "/") { //do it 32 | } 33 | }) 34 | ``` 35 | 36 | ##### Environment variables (*put your keys in here*) 37 | ``` 38 | process.env.oktaOrg 39 | ``` 40 | 41 | ##### Promises func (*this is how I make all my functions*) 42 | ``` 43 | $FUNCTIONNAME$ = function ( requestObj ) { 44 | return new Promise ( (resolve, reject)=> { 45 | 46 | resolve ( requestObj) 47 | }) 48 | } 49 | ``` 50 | 51 | #### Readfile 52 | ``` 53 | fs.readFile('./saml.txt', function read(err, data) { 54 | if (err) { 55 | throw err; 56 | } 57 | } 58 | ``` 59 | 60 | #### Base64 Decode 61 | ``` 62 | let buff = new Buffer(body, 'base64'); //base 64decode 63 | ``` 64 | 65 | #### 66 | 67 | #### Url Decode 68 | ``` 69 | var decode = require('urldecode') 70 | 71 | body = decode(body) //url decode 72 | ``` 73 | 74 | -------------------------------------------------------------------------------- /oktaServer/readme.md: -------------------------------------------------------------------------------- 1 | ### This is the Dockerfile I used to build Docker Images that supported Okta Agent for LDAP or On Premise Provisioning. 2 | 3 | ``` 4 | FROM centos:7 5 | ENV container docker 6 | ENV GOPATH /root 7 | 8 | 9 | RUN printf " _ _ \n ___ | |__| |_ __ _ \n / _ \| / /| _|/ _\` |\n \___/|_\_\ \__|\__,_\n" 10 | 11 | 12 | RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in ; do [ $i == \ 13 | systemd-tmpfiles-setup.service ] || rm -f $i; done); \ 14 | rm -f /lib/systemd/system/multi-user.target.wants/;\ 15 | rm -f /etc/systemd/system/.wants/;\ 16 | rm -f /lib/systemd/system/local-fs.target.wants/; \ 17 | rm -f /lib/systemd/system/sockets.target.wants/udev; \ 18 | rm -f /lib/systemd/system/sockets.target.wants/initctl; \ 19 | rm -f /lib/systemd/system/basic.target.wants/;\ 20 | rm -f /lib/systemd/system/anaconda.target.wants/*; 21 | 22 | 23 | #RUN mkdir /okta 24 | ADD https://companyx-admin.okta.com/static/agents/ProvisioningAgent/OktaProvisioningAgent-01.01.00.x86_64.rpm / 25 | ADD https://raw.githubusercontent.com/pmcdowell-okta/golangOktaScimServer/master/goLangScimServer.linux / 26 | RUN chmod 777 /goLangScimServer.linux 27 | RUN chmod +x /goLangScimServer.linux 28 | RUN yum update -y 29 | RUN yum clean all 30 | 31 | 32 | #Don't need JDK, but just incase anyone still uses Java 33 | RUN yum install -y java-1.7.0-openjdk 34 | 35 | 36 | RUN yum install -y wget curl nc git golang 37 | RUN echo Download Gorilla Stuff 38 | RUN go get github.com/gorilla/mux 39 | RUN go get github.com/gorilla/sessions 40 | 41 | 42 | RUN git clone https://github.com/pmcdowell-okta/golangOktaScimServer.git 43 | 44 | 45 | #installing wget, curl, and netCat for testing ! 46 | 47 | 48 | RUN yum -y install initscripts 49 | 50 | 51 | #this makes the service commands work in CentOs 52 | 53 | 54 | VOLUME [ "/sys/fs/cgroup" ] 55 | CMD ["/usr/sbin/init"] 56 | 57 | ``` 58 | 59 | -------------------------------------------------------------------------------- /awsSamOktaGuest/src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var http = require("https"); 4 | 5 | var username = "xxx" 6 | var password = "xxx" 7 | var oktaOrg = "companyx.okta.com" 8 | 9 | exports.handler = (event, context, callback) => { 10 | 11 | getToken().then(function(token) { 12 | 13 | var response = { 14 | statusCode: 307, 15 | headers: { 16 | "Location": "https://"+oktaOrg+"/login/sessionCookieRedirect?token=" + token +"&redirectUrl=https://"+oktaOrg 17 | }, 18 | body: null 19 | }; 20 | callback(null, response); 21 | 22 | }) 23 | }; 24 | 25 | function getToken() { 26 | 27 | return new Promise((resolve, reject) => { 28 | 29 | 30 | var options = { 31 | "method": "POST", 32 | "hostname": oktaOrg, 33 | "port": null, 34 | "path": "/api/v1/authn", 35 | "headers": { 36 | "accept": "application/json", 37 | "content-type": "application/json", 38 | "cache-control": "no-cache", 39 | "postman-token": "d35c74e1-471b-ef66-5cee-077c6b4bfbf9" 40 | } 41 | }; 42 | 43 | var req = http.request(options, function(res) { 44 | var chunks = []; 45 | 46 | res.on("data", function(chunk) { 47 | chunks.push(chunk); 48 | }); 49 | 50 | res.on("end", function() { 51 | var body = Buffer.concat(chunks); 52 | body = JSON.parse(body.toString()) 53 | resolve(body.sessionToken); 54 | }); 55 | }); 56 | 57 | req.write(JSON.stringify({ 58 | username: username, 59 | password: password, 60 | options: { 61 | multiOptionalFactorEnroll: true, 62 | warnBeforePasswordExpired: true 63 | } 64 | })); 65 | req.end(); 66 | }) 67 | } 68 | 69 | 70 | -------------------------------------------------------------------------------- /awsOktaRentalWithAuthorizer/readme.md: -------------------------------------------------------------------------------- 1 | ### AWS SAM/Cloudformation backend for Okta Rental (With Authorizer example) ! 2 | 3 | This is the same example as the previous OktaRental example, 4 | with the addition of an Authorizer. It took me a while to get it 5 | working, maybe it will help someone else. 6 | 7 | Create an **S3 Bucket** the command is: `aws s3 mb s3://oktarental123` 8 | 9 | #### To deploy to this: 10 | 11 | `./deploy.sh oktarental123 oktarental123 template.yaml` 12 | 13 | #### Results: 14 | ``` 15 | Execute the following command to deploy the packaged template 16 | aws cloudformation deploy --template-file /Users/patrickmcdowell/Box Sync/c-=Code=-/cloudformationOktaRental/output.yaml --stack-name 17 | Waiting for changeset to be created.. 18 | Waiting for stack create/update to complete 19 | Successfully created/updated stack - oktarental123 20 | 21 | Test in browser: https://bedfy62k98.execute-api.us-east-1.amazonaws.com/dev/ 22 | Vehicles API 23 | Test in browser: https://bedfy62k98.execute-api.us-east-1.amazonaws.com/dev/vehicles 24 | Bookings API 25 | Test in browser: https://bedfy62k98.execute-api.us-east-1.amazonaws.com/dev/bookings 26 | 27 | To Delete the Stack use this command 28 | aws cloudformation delete-stack --stack-name oktarental123 29 | ``` 30 | 31 | #### Test: 32 | 33 | You will need to include an Authorization Header in this one for it to work. 34 | 35 | 36 | ``` 37 | curl -H "Authorization:Bearer 34223" https://bedfy62k98.execute-api.us-east-1.amazonaws.com/dev/vehicles 38 | 39 | {"inventory":[{"id":"112345","make":"Jeep","model":"Wrangler","class":"Offroad","desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, 4x4, Removable Top, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Mirrors,............. 40 | ``` 41 | 42 | #### Delete your stack when you are done 43 | 44 | You can do this from the AWS Console, or issue the command provided by the deploy.sh script. 45 | 46 | `aws cloudformation delete-stack --stack-name oktarental123 47 | ` 48 | 49 | 50 | -------------------------------------------------------------------------------- /javascriptPromises/readme.md: -------------------------------------------------------------------------------- 1 | # Promises 2 | 3 | ## Simple example: 4 | 5 | ``` 6 | new Promise ( (resolve)=>{ 7 | console.log("hi") 8 | resolve ( "done"); 9 | }).then ( function( result) { 10 | console.log(result) 11 | }).then ( function() { 12 | console.log("totally done") 13 | }) 14 | ``` 15 | 16 | ## better example: 17 | 18 | ``` 19 | var firstMethod = function() { 20 | var promise = new Promise(function(resolve, reject){ 21 | setTimeout(function() { 22 | console.log('first method completed'); 23 | resolve({data: '123'}); 24 | }, 2000); 25 | }); 26 | return promise; 27 | }; 28 | 29 | 30 | var secondMethod = function(someStuff) { 31 | var promise = new Promise(function(resolve, reject){ 32 | setTimeout(function() { 33 | console.log('second method completed'); 34 | resolve({newData: someStuff.data + ' some more data'}); 35 | }, 2000); 36 | }); 37 | return promise; 38 | }; 39 | 40 | var thirdMethod = function(someStuff) { 41 | var promise = new Promise(function(resolve, reject){ 42 | setTimeout(function() { 43 | console.log('third method completed'); 44 | resolve({result: someStuff.newData}); 45 | }, 3000); 46 | }); 47 | return promise; 48 | }; 49 | 50 | firstMethod() 51 | .then(secondMethod) 52 | .then(thirdMethod); 53 | ``` 54 | 55 | ## I struggled with Promises, but I use this for a reference when I forget how things work. 56 | 57 | It runs test1, then runs test2 after. 58 | 59 | ``` 60 | 61 | 81 | 82 | ``` 83 | -------------------------------------------------------------------------------- /awsSamOktaRental/readme.md: -------------------------------------------------------------------------------- 1 | ### AWS SAM/Cloudformation backend for Okta Rental ! 2 | 3 | This is a simple **SAM/Cloudformation** template to deploy a simple Amazon API Gateway with two 4 | Lambda functions for bookings and available vehicles. 5 | 6 | If this is your first time getting going with SAM Templates, this might help you get going. 7 | You will need to install the AWS CLI Tools, and install SAM. See my other tutorials https://github.com/pmcdowell-okta/my-notes 8 | 9 | Create an **S3 Bucket** the command is: `aws s3 mb s3://oktarental123` 10 | 11 | #### To deploy to this: 12 | 13 | `./deploy.sh oktarental123 oktarental123 template.yaml` 14 | 15 | #### Results: 16 | ``` 17 | Execute the following command to deploy the packaged template 18 | aws cloudformation deploy --template-file /Users/patrickmcdowell/Box Sync/c-=Code=-/cloudformationOktaRental/output.yaml --stack-name 19 | Waiting for changeset to be created.. 20 | Waiting for stack create/update to complete 21 | Successfully created/updated stack - oktarental123 22 | 23 | Test in browser: https://bedfy62k98.execute-api.us-east-1.amazonaws.com/dev/ 24 | Vehicles API 25 | Test in browser: https://bedfy62k98.execute-api.us-east-1.amazonaws.com/dev/vehicles 26 | Bookings API 27 | Test in browser: https://bedfy62k98.execute-api.us-east-1.amazonaws.com/dev/bookings 28 | 29 | To Delete the Stack use this command 30 | aws cloudformation delete-stack --stack-name oktarental123 31 | ``` 32 | 33 | #### Test: 34 | 35 | You can test it with CURL, or use your browser, the valid URLs will be returned to you 36 | 37 | ``` 38 | curl https://bedfy62k98.execute-api.us-east-1.amazonaws.com/dev/vehicles 39 | 40 | {"inventory":[{"id":"112345","make":"Jeep","model":"Wrangler","class":"Offroad","desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, 4x4, Removable Top, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Mirrors,............. 41 | ``` 42 | 43 | #### Delete your stack when you are done 44 | 45 | You can do this from the AWS Console, or issue the command provided by the deploy.sh script. 46 | 47 | `aws cloudformation delete-stack --stack-name oktarental123 48 | ` 49 | 50 | 51 | -------------------------------------------------------------------------------- /awsCloudformationRunLambda/cfn-response.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Amazon Web Services, Inc. or its affiliates. All Rights Reserved. 2 | This file is licensed to you under the AWS Customer Agreement (the "License"). 3 | You may not use this file except in compliance with the License. 4 | A copy of the License is located at http://aws.amazon.com/agreement/ . 5 | This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. 6 | See the License for the specific language governing permissions and limitations under the License. */ 7 | 8 | exports.SUCCESS = "SUCCESS"; 9 | exports.FAILED = "FAILED"; 10 | 11 | exports.send = function(event, context, responseStatus, responseData, physicalResourceId, noEcho) { 12 | 13 | var responseBody = JSON.stringify({ 14 | Status: responseStatus, 15 | Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName, 16 | PhysicalResourceId: physicalResourceId || context.logStreamName, 17 | StackId: event.StackId, 18 | RequestId: event.RequestId, 19 | LogicalResourceId: event.LogicalResourceId, 20 | NoEcho: noEcho || false, 21 | Data: responseData 22 | }); 23 | 24 | console.log("Response body:\n", responseBody); 25 | 26 | var https = require("https"); 27 | var url = require("url"); 28 | 29 | var parsedUrl = url.parse(event.ResponseURL); 30 | var options = { 31 | hostname: parsedUrl.hostname, 32 | port: 443, 33 | path: parsedUrl.path, 34 | method: "PUT", 35 | headers: { 36 | "content-type": "", 37 | "content-length": responseBody.length 38 | } 39 | }; 40 | 41 | var request = https.request(options, function(response) { 42 | console.log("Status code: " + response.statusCode); 43 | console.log("Status message: " + response.statusMessage); 44 | context.done(); 45 | }); 46 | 47 | request.on("error", function(error) { 48 | console.log("send(..) failed executing https.request(..): " + error); 49 | context.done(); 50 | }); 51 | 52 | request.write(responseBody); 53 | request.end(); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/setups3bucket/cfn-response.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Amazon Web Services, Inc. or its affiliates. All Rights Reserved. 2 | This file is licensed to you under the AWS Customer Agreement (the "License"). 3 | You may not use this file except in compliance with the License. 4 | A copy of the License is located at http://aws.amazon.com/agreement/ . 5 | This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. 6 | See the License for the specific language governing permissions and limitations under the License. */ 7 | 8 | exports.SUCCESS = "SUCCESS"; 9 | exports.FAILED = "FAILED"; 10 | 11 | exports.send = function(event, context, responseStatus, responseData, physicalResourceId, noEcho) { 12 | 13 | var responseBody = JSON.stringify({ 14 | Status: responseStatus, 15 | Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName, 16 | PhysicalResourceId: physicalResourceId || context.logStreamName, 17 | StackId: event.StackId, 18 | RequestId: event.RequestId, 19 | LogicalResourceId: event.LogicalResourceId, 20 | NoEcho: noEcho || false, 21 | Data: responseData 22 | }); 23 | 24 | console.log("Response body:\n", responseBody); 25 | 26 | var https = require("https"); 27 | var url = require("url"); 28 | 29 | var parsedUrl = url.parse(event.ResponseURL); 30 | var options = { 31 | hostname: parsedUrl.hostname, 32 | port: 443, 33 | path: parsedUrl.path, 34 | method: "PUT", 35 | headers: { 36 | "content-type": "", 37 | "content-length": responseBody.length 38 | } 39 | }; 40 | 41 | var request = https.request(options, function(response) { 42 | console.log("Status code: " + response.statusCode); 43 | console.log("Status message: " + response.statusMessage); 44 | context.done(); 45 | }); 46 | 47 | request.on("error", function(error) { 48 | console.log("send(..) failed executing https.request(..): " + error); 49 | context.done(); 50 | }); 51 | 52 | request.write(responseBody); 53 | request.end(); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /awsLaunchStack/readme.md: -------------------------------------------------------------------------------- 1 | ### Deploying Applications using AWS **Launch Stack** 2 | 3 | This concept seemed like Black Magic to me at first. 4 | 5 | Once I started to get a handle on SAM Serverless Yaml 6 | files, this started to make sense. 7 | 8 | I'll add more notes, but basically you need to create an 9 | yaml file (like I did in the project). I just copied the 10 | sample code from Amazon. 11 | 12 | You'll need to put that yaml file on S3, if you are new 13 | to AWS, use this command to create an S3 Bucket. 14 | 15 | `aws s3 mb s3://launchstack123` 16 | 17 | Then copy the launchstack.yaml file to that **S3** Bucket 18 | 19 | `aws s3 cp ./launchstack.yaml s3://launchstack123` 20 | 21 | Now, you will need to make that public if you want others 22 | to do that, I won't go through those steps, but just go to 23 | AWS **S3**, and make it public from the GUI. 24 | 25 | Then you warp it up with a long URL 26 | 27 | ``` 28 | https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=myteststack&templateURL=PUT_THE_LINK_TO_YOUR_S3_BUCKET_AND_FILE_HRE 29 | ``` 30 | 31 | Mine looked like this when I was all done: 32 | 33 | https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=myteststack&templateURL=https://s3.amazonaws.com/launchstack123/launchstack.yaml 34 | 35 | #### Getting Fancy 36 | 37 | If you got this far, why not go all the way.. Create a pretty link to 38 | that URL.. This the code you would put in a MarkDown file if you want 39 | a nice graphic to show up that says click to launch. 40 | 41 | ``` 42 | [](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=myteststack&templateURL=https://awscomputeblogimages.s3-us-west-2.amazonaws.com/samfarm-website.yaml) 43 | ``` 44 | 45 | #### It will look like this Now ! 46 | 47 | *----- SAMPLE -----* 48 | 49 | [](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=myteststack&templateURL=https://awscomputeblogimages.s3-us-west-2.amazonaws.com/samfarm-website.yaml) 50 | 51 | *----- SAMPLE -----* 52 | 53 | Hope this helps someone -------------------------------------------------------------------------------- /oktaMultipleLoginPage/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {{pageTitle}} 9 | {{{SignInWidgetResources}}} 10 | 11 | 12 |

22 | 27 | 28 | 44 | 45 | 46 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /awsSamOktaRental/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: AWS SAM Tutorial 4 | Parameters: 5 | Environment: 6 | Type: String 7 | Default: dev 8 | StageName: 9 | Type: String 10 | Default: prod 11 | Description: The Lambda Function and API Gateway Stage 12 | 13 | Outputs: 14 | ExampleAPIUrl: 15 | Value: !Sub "https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/" 16 | 17 | Resources: 18 | HelloAPI: 19 | Type: AWS::Serverless::Api 20 | Properties: 21 | StageName: !Sub ${Environment} 22 | DefinitionBody: 23 | swagger: 2.0 24 | info: 25 | title: 26 | Ref: AWS::StackName 27 | paths: 28 | /vehicles: 29 | get: 30 | x-amazon-apigateway-integration: 31 | httpMethod: POST 32 | type: aws_proxy 33 | uri: 34 | !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VehiclesLambda.Arn}/invocations 35 | responses: {} 36 | /bookings: 37 | get: 38 | x-amazon-apigateway-integration: 39 | httpMethod: POST 40 | type: aws_proxy 41 | uri: 42 | !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${BookingsLambda.Arn}/invocations 43 | responses: {} 44 | VehiclesLambda: 45 | Type: AWS::Serverless::Function 46 | Properties: 47 | FunctionName: !Sub VehiclesLambda-${Environment} 48 | Handler: index.handler 49 | Runtime: nodejs4.3 50 | CodeUri: vehicles 51 | MemorySize: 128 52 | Timeout: 30 53 | Policies: 54 | - AWSLambdaBasicExecutionRole 55 | - AmazonDynamoDBFullAccess 56 | Events: 57 | MyEndpoint: 58 | Type: Api 59 | Properties: 60 | Path: /vehicles 61 | Method: GET 62 | RestApiId: 63 | Ref: HelloAPI 64 | 65 | BookingsLambda: 66 | Type: AWS::Serverless::Function 67 | Properties: 68 | FunctionName: !Sub BookingsLambda-${Environment} 69 | Handler: index.handler 70 | Runtime: nodejs4.3 71 | CodeUri: bookings 72 | MemorySize: 128 73 | Timeout: 30 74 | Policies: 75 | - AWSLambdaBasicExecutionRole 76 | - AmazonDynamoDBFullAccess 77 | Events: 78 | MyEndpoint: 79 | Type: Api 80 | Properties: 81 | Path: /bookings 82 | Method: GET 83 | RestApiId: 84 | Ref: HelloAPI 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /awsSam/03-sam-swagger-auth-template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: An example serverless "Hello World2 " application with a custom authorizer. 4 | 5 | Parameters: 6 | AutoPublishAliasName: 7 | Type: String 8 | Default: current 9 | Description: The alias used for Auto Publishing 10 | StageName: 11 | Type: String 12 | Default: prod 13 | Description: The Lambda Function and API Gateway Stage 14 | FunctionName: 15 | Type: String 16 | Default: Example 17 | Description: The Lambda Function Name 18 | 19 | Outputs: 20 | ExampleAPIUrl: 21 | Value: !Sub "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/" 22 | 23 | Resources: 24 | ApiGateway: 25 | Type: AWS::Serverless::Api 26 | Properties: 27 | StageName: Prod 28 | DefinitionBody: 29 | swagger: 2.0 30 | info: 31 | title: 32 | Ref: AWS::StackName 33 | securityDefinitions: 34 | test-authorizer: 35 | type: apiKey 36 | name: Authorization 37 | in: header 38 | x-amazon-apigateway-authtype: custom 39 | x-amazon-apigateway-authorizer: 40 | type: token 41 | authorizerUri: 42 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${TestAuthorizerFunc.Arn}/invocations 43 | authorizerResultTtlInSeconds: 5 44 | paths: 45 | "/": 46 | get: 47 | x-amazon-apigateway-integration: 48 | httpMethod: post 49 | type: aws_proxy 50 | uri: 51 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloWorld.Arn}/invocations 52 | responses: {} 53 | security: 54 | - test-authorizer: [] 55 | 56 | HelloWorld: 57 | Type: AWS::Serverless::Function 58 | Properties: 59 | Handler: lambda_function.lambda_handler 60 | Runtime: python3.6 61 | CodeUri: ./HelloWorld 62 | Events: 63 | GetApi: 64 | Type: Api 65 | Properties: 66 | Path: / 67 | Method: get 68 | RestApiId: 69 | Ref: ApiGateway 70 | 71 | TestAuthorizerFunc: 72 | Type: AWS::Serverless::Function 73 | Properties: 74 | Handler: lambda_function.lambda_handler 75 | Runtime: python3.6 76 | CodeUri: ./TestAuthorizerFunc 77 | 78 | TestAuthorizerFuncPerm: 79 | Type: AWS::Lambda::Permission 80 | DependsOn: 81 | - ApiGateway 82 | - TestAuthorizerFunc 83 | Properties: 84 | Action: lambda:InvokeFunction 85 | FunctionName: 86 | Ref: TestAuthorizerFunc 87 | Principal: apigateway.amazonaws.com 88 | -------------------------------------------------------------------------------- /oktaMultipleLoginPage/readme.md: -------------------------------------------------------------------------------- 1 | ### Host multiple page using SPA and Custom login page 2 | 3 | #### How to use this 4 | 5 | It's pretty basic, if you want to see the default login page just hit the URL. 6 | 7 | If you add a switch to your request like this `https://sso.oktapatrick.com?pony` 8 | the source will look for a hidden **
** with the same name, and 9 | display that **
**. 10 | 11 | Just add your additional pages to the switch case, and you should be up an running. 12 | 13 | ``` 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | {{pageTitle}} 22 | {{{SignInWidgetResources}}} 23 | 24 | 25 | 35 | 40 | 41 | 57 | 58 | 59 | 79 | 80 | 81 | 82 | ``` -------------------------------------------------------------------------------- /awsCloudformationCustomResourceOrchestration/readme.md: -------------------------------------------------------------------------------- 1 | ### Orchestrating Custom Resource in Cloudformation 2 | 3 | My usecase had two Custom Resources, one needed to be run before 4 | the other. This template shows how to take the output from one 5 | Custom Resource and feed it into another Custom Resource. 6 | 7 | ``` 8 | AWSTemplateFormatVersion: 2010-09-09 9 | Transform: AWS::Serverless-2016-10-31 10 | Description: Run Lambda1, then run Lambda2 w/ outpu from Lambda1 11 | 12 | 13 | Resources: 14 | lambda1: 15 | Type: Custom::test 16 | Properties: 17 | ServiceToken: arn:aws:lambda:us-east-1:761861444952:function:runOnce 18 | 19 | lambda2: 20 | Type: Custom::test2 21 | Properties: 22 | ServiceToken: arn:aws:lambda:us-east-1:761861444952:function:runOnce 23 | myParameter: !GetAtt lambda1.test 24 | 25 | ``` 26 | 27 | #### Not Recommended 28 | 29 | If you want to jam everything in a single template, you might be able to use a 30 | lambda function like this, which includes the **cnf-response.js** 31 | 32 | **Just Experimenting, making it easier for others to deploy** 33 | 34 | ``` 35 | exports.SUCCESS = "SUCCESS"; 36 | exports.FAILED = "FAILED"; 37 | 38 | exports.send = function(event, context, responseStatus, responseData, physicalResourceId, noEcho) { 39 | 40 | var responseBody = JSON.stringify({ 41 | Status: responseStatus, 42 | Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName, 43 | PhysicalResourceId: physicalResourceId || context.logStreamName, 44 | StackId: event.StackId, 45 | RequestId: event.RequestId, 46 | LogicalResourceId: event.LogicalResourceId, 47 | NoEcho: noEcho || false, 48 | Data: responseData 49 | }); 50 | 51 | console.log("Response body:\n", responseBody); 52 | 53 | var https = require("https"); 54 | var url = require("url"); 55 | 56 | var parsedUrl = url.parse(event.ResponseURL); 57 | var options = { 58 | hostname: parsedUrl.hostname, 59 | port: 443, 60 | path: parsedUrl.path, 61 | method: "PUT", 62 | headers: { 63 | "content-type": "", 64 | "content-length": responseBody.length 65 | } 66 | }; 67 | 68 | var request = https.request(options, function(response) { 69 | console.log("Status code: " + response.statusCode); 70 | console.log("Status message: " + response.statusMessage); 71 | context.done(); 72 | }); 73 | 74 | request.on("error", function(error) { 75 | console.log("send(..) failed executing https.request(..): " + error); 76 | context.done(); 77 | }); 78 | 79 | request.write(responseBody); 80 | request.end(); 81 | } 82 | 83 | 84 | 85 | exports.handler = (event, context, callback) => { 86 | console.log ( event ); 87 | //I use this to check that parameter is getting passed in 88 | console.log("runOnceRan!"); 89 | exports.send(event, context, exports.SUCCESS, {"test":"key23"}); 90 | // All it does is return parameter key23 91 | }; 92 | 93 | ``` -------------------------------------------------------------------------------- /awsSamOktaGuest/readme.md: -------------------------------------------------------------------------------- 1 | ## SAM / Cloudformation (Okta Guest) 2 | 3 | Create a guest account that people can use to log into Okta, 4 | just send them to the URL created by the deployment script, 5 | and the user will be logged in. 6 | 7 | ### To Deploy do this 8 | 9 | `./deploy.sh YOURS3BUCKETNAME YOURSTACKNAME template.yaml` 10 | 11 | ##### If you forget how to create an S3 bucket do this: 12 | `aws s3 mb s3://YOURBUCKETNAME` 13 | 14 | If everything works as it should, you will see a response like this: 15 | 16 | ``` 17 | Waiting for changeset to be created.. 18 | Waiting for stack create/update to complete 19 | Successfully created/updated stack - chenr2r2 20 | 21 | Test in browser: https://zv27pqu5x9.execute-api.us-east-1.amazonaws.com/dev/ 22 | 23 | To Delete the Stack use this command 24 | aws cloudformation delete-stack --stack-name YOURSTACKNAME 25 | ``` 26 | ### Test 27 | 28 | You can test with curl like this `curl https://zv27pqu5x9.execute-api.us-east-1.amazonaws.com/dev/test` 29 | 30 | the response should look like this: 31 | ``` 32 | "Cool you got response" 33 | ``` 34 | 35 | The Lambda function, is pretty much a stock Lambda function for the API Gateway 36 | 37 | ``` 38 | 'use strict' 39 | 40 | var http = require("https"); 41 | 42 | var username = "xxx" 43 | var password = "xxx" 44 | var oktaOrg = "companyx.okta.com" 45 | 46 | exports.handler = (event, context, callback) => { 47 | 48 | getToken().then(function(token) { 49 | 50 | var response = { 51 | statusCode: 307, 52 | headers: { 53 | "Location": "https://"+oktaOrg+"/login/sessionCookieRedirect?token=" + token +"&redirectUrl=https://"+oktaOrg 54 | }, 55 | body: null 56 | }; 57 | callback(null, response); 58 | 59 | }) 60 | }; 61 | 62 | function getToken() { 63 | 64 | return new Promise((resolve, reject) => { 65 | 66 | 67 | var options = { 68 | "method": "POST", 69 | "hostname": oktaOrg, 70 | "port": null, 71 | "path": "/api/v1/authn", 72 | "headers": { 73 | "accept": "application/json", 74 | "content-type": "application/json", 75 | "cache-control": "no-cache", 76 | "postman-token": "d35c74e1-471b-ef66-5cee-077c6b4bfbf9" 77 | } 78 | }; 79 | 80 | var req = http.request(options, function(res) { 81 | var chunks = []; 82 | 83 | res.on("data", function(chunk) { 84 | chunks.push(chunk); 85 | }); 86 | 87 | res.on("end", function() { 88 | var body = Buffer.concat(chunks); 89 | body = JSON.parse(body.toString()) 90 | resolve(body.sessionToken); 91 | }); 92 | }); 93 | 94 | req.write(JSON.stringify({ 95 | username: username, 96 | password: password, 97 | options: { 98 | multiOptionalFactorEnroll: true, 99 | warnBeforePasswordExpired: true 100 | } 101 | })); 102 | req.end(); 103 | }) 104 | } 105 | 106 | ``` 107 | -------------------------------------------------------------------------------- /lambdaEdgeSetCookie/readme.md: -------------------------------------------------------------------------------- 1 | I did some interesting work with Lambda Edge, in this case I used 2 | the lambda Edge to determine if a User has a cookie, if they 3 | did not, it set the cookie to a JWT. I'll likely put more examples 4 | up, but thought this might help someone. 5 | 6 | 7 | 8 | ``` 9 | 'use strict'; 10 | 11 | let content = ` 12 | <\!DOCTYPE html> 13 | 12 14 | 15 | 16 | 17 | Simple Lambda@Edge Static Content Response 18 | 19 | 20 |

Hello from Lambda@Edge!

21 | 22 | 23 | `; 24 | 25 | exports.handler = (event, context, callback) => { 26 | /* 27 | * Generate HTTP OK response using 200 status code with HTML body. 28 | */ 29 | 30 | // console.log(event) 31 | 32 | const request = event.Records[0].cf.request; 33 | const headers = request.headers; 34 | var resultr = "" 35 | 36 | console.log ("in lambda"); 37 | 38 | if (headers.cookie) { 39 | console.log("in 30") 40 | 41 | for (let i = 0; i < headers.cookie.length; i++) { 42 | if (headers.cookie[i].value.indexOf("jwt") >= 0) { 43 | console.log('on line 26'); 44 | resultr="You have a cookie on line 26" 45 | break; 46 | } else { 47 | console.log("Not on line 26, on line 29") 48 | } 49 | } 50 | } else { 51 | resultr="You have No cookie, I gave you one" 52 | 53 | console.log("No Cookie :") 54 | 55 | } 56 | 57 | 58 | 59 | const response = { 60 | status: '200', 61 | statusDescription: 'OK', 62 | headers: { 63 | 'cache-control': [{ 64 | key: 'Cache-Control', 65 | value: 'max-age=100' 66 | }], 67 | 'content-type': [{ 68 | key: 'Content-Type', 69 | value: 'text/html' 70 | }], 71 | 'content-encoding': [{ 72 | key: 'Content-Encoding', 73 | value: 'UTF-8' 74 | }], 75 | 'set-cookie': [{ 76 | key: 'Set-Cookie', 77 | value: `jwt=eyJraWQiOiJkZFBVRER5VXBIMk41d0dTWHZucVFaeS1PbVRGU1Z1NVBZYW5zanBzb0FzIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIwMHUxOGVlaHUzNDlhUzJ5WDFkOCIsIm5hbWUiOiJva3RhcHJveHkgb2t0YXByb3h5IiwidmVyIjoxLCJpc3MiOiJodHRwczovL2NvbXBhbnl4Lm9rdGEuY29tIiwiYXVkIjoidlpWNkNwOHJuNWx4ck45YVo2ODgiLCJpYXQiOjE1MjM5MTMyNTgsImV4cCI6MTUyMzkxNjg1OCwianRpIjoiSUQuMW1Od0xSbEQ4X2ZsLUFfMHN4QzdIZTVIdVU4Zm0xQU1DR0dsU2ZjelltTSIsImFtciI6WyJwd2QiXSwiaWRwIjoiMDBveTc0YzBnd0hOWE1SSkJGUkkiLCJub25jZSI6Im4tMFM2X1d6QTJNaiIsInByZWZlcnJlZF91c2VybmFtZSI6Im9rdGFwcm94eUBva3RhLmNvbSIsImF1dGhfdGltZSI6MTUyMzkxMzI1MywiYXRfaGFzaCI6IllPX0J1MWMxRGxkbEdieHJWdHZSZkEifQ.MfkLPHevfEaLjM1FZh6vIFcBVuUFx0PqTxSia0X54OQhaJdvu0OOT8YtLrqUcqIlywwcYKtKRP5XBLSFAuphWbAJGvf1wPK_kJBRYTINi4264Ta1EtNC9BM_lcUitWTV0yNNDGNbpCOYBlO-LqOJB4VLOmXswbo6QGj36TujgChRZclG5w25s2SCj6si_TsgvDKsQX0k-eaAgziBSu0APRyVwEl0xiGukfNYD1bdVTjz0Q_UykX2fnzI6Y_Tw__A5_e-ZPy4bgH0tigFYut9yJP-Yf4aomY7xS95Y_89bDQStHtJGxLMFrWL6fq4wrwufOOe_rg9dok8kVUTUUDgjQ; Path=/` 78 | }], 79 | }, 80 | body: resultr, 81 | }; 82 | callback(null, response); 83 | }; 84 | 85 | ``` 86 | 87 | -------------------------------------------------------------------------------- /awsOktaRentalWithAuthorizer/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: Yes you can use SAM to create an Authorizer 4 | Parameters: 5 | Environment: 6 | Type: String 7 | Default: dev 8 | StageName: 9 | Type: String 10 | Default: prod 11 | Description: The Lambda Function and API Gateway Stage 12 | 13 | Outputs: 14 | ExampleAPIUrl: 15 | Value: !Sub "https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/" 16 | 17 | Resources: 18 | HelloAPI: 19 | Type: AWS::Serverless::Api 20 | Properties: 21 | StageName: !Sub ${Environment} 22 | DefinitionBody: 23 | swagger: 2.0 24 | info: 25 | title: 26 | Ref: AWS::StackName 27 | securityDefinitions: 28 | test-authorizer: 29 | type: apiKey 30 | name: Authorization 31 | in: header 32 | x-amazon-apigateway-authtype: custom 33 | x-amazon-apigateway-authorizer: 34 | type: token 35 | authorizerUri: 36 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${AuthorizerFunc.Arn}/invocations 37 | authorizerResultTtlInSeconds: 5 38 | paths: 39 | /vehicles: 40 | get: 41 | x-amazon-apigateway-integration: 42 | httpMethod: POST 43 | type: aws_proxy 44 | uri: 45 | !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VehiclesLambda.Arn}/invocations 46 | responses: {} 47 | security: 48 | - test-authorizer: [] 49 | /bookings: 50 | get: 51 | x-amazon-apigateway-integration: 52 | httpMethod: POST 53 | type: aws_proxy 54 | uri: 55 | !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${BookingsLambda.Arn}/invocations 56 | responses: {} 57 | VehiclesLambda: 58 | Type: AWS::Serverless::Function 59 | Properties: 60 | FunctionName: !Sub VehiclesLambda-${Environment} 61 | Handler: index.handler 62 | Runtime: nodejs4.3 63 | CodeUri: vehicles 64 | MemorySize: 128 65 | Timeout: 30 66 | Policies: 67 | - AWSLambdaBasicExecutionRole 68 | - AmazonDynamoDBFullAccess 69 | Events: 70 | MyEndpoint: 71 | Type: Api 72 | Properties: 73 | Path: /vehicles 74 | Method: GET 75 | RestApiId: 76 | Ref: HelloAPI 77 | 78 | BookingsLambda: 79 | Type: AWS::Serverless::Function 80 | Properties: 81 | FunctionName: !Sub BookingsLambda-${Environment} 82 | Handler: index.handler 83 | Runtime: nodejs4.3 84 | CodeUri: bookings 85 | MemorySize: 128 86 | Timeout: 30 87 | Policies: 88 | - AWSLambdaBasicExecutionRole 89 | - AmazonDynamoDBFullAccess 90 | Events: 91 | MyEndpoint: 92 | Type: Api 93 | Properties: 94 | Path: /bookings 95 | Method: GET 96 | RestApiId: 97 | Ref: HelloAPI 98 | 99 | AuthorizerFunc: 100 | Type: AWS::Serverless::Function 101 | Properties: 102 | Handler: authorizer.authorizer 103 | Runtime: nodejs4.3 104 | CodeUri: ./authorizer 105 | 106 | AuthorizerFuncPerm: 107 | Type: AWS::Lambda::Permission 108 | DependsOn: 109 | - HelloAPI 110 | - AuthorizerFunc 111 | Properties: 112 | Action: lambda:InvokeFunction 113 | FunctionName: 114 | Ref: AuthorizerFunc 115 | Principal: apigateway.amazonaws.com 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/setups3bucket/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var AWS = require('aws-sdk'); 4 | var fs = require('fs'); 5 | var s3 = new AWS.S3(); 6 | var response = require ('cfn-response') 7 | 8 | var oktaOrg = "" 9 | var myBucket = "" 10 | var myKey = 'index.html'; 11 | 12 | 13 | let createS3Bucket = function(bucketname, callback) { 14 | return new Promise(function(resolve, reject) { 15 | s3.createBucket({ Bucket: bucketname, ACL: 'public-read' }, function(err, data) { 16 | if (err) { 17 | console.log(err) 18 | 19 | if (err.code == "BucketAlreadyExists") { //no sweat.. already there 20 | resolve() 21 | } 22 | else { //maybe bucketname didn't meet requirements ? 23 | reject ( err ) 24 | } 25 | } else { 26 | resolve () 27 | } 28 | }); 29 | 30 | }); 31 | } 32 | 33 | let createIndexFile = function(nameOfBucket, nameOfFile, callback) { 34 | return new Promise(function(resolve, reject) { 35 | var fileBuffer = fs.readFileSync("oktaLoginPage.html"); 36 | var metaData = 'text/html'; 37 | 38 | var fileString = fileBuffer.toString() 39 | fileString = fileString.replace( "{oktaOrg}","https://"+oktaOrg) 40 | var buf = Buffer.from(fileString, 'utf-8'); 41 | 42 | s3.putObject({ 43 | ACL: 'public-read', 44 | Bucket: nameOfBucket, 45 | Key: nameOfFile, 46 | Body: buf, 47 | ContentType: metaData 48 | }, function(error, response2) { 49 | resolve('done') 50 | 51 | }); 52 | }) 53 | } 54 | 55 | let deleteS3Bucket = function(bucketname, callback) { 56 | return new Promise(function(resolve, reject) { 57 | var params = { 58 | Bucket: bucketname, 59 | Delete: { // required 60 | Objects: [ // required 61 | { 62 | Key: myKey // required 63 | } 64 | ], 65 | }, 66 | }; 67 | 68 | s3.deleteObjects(params, function(err, data) { 69 | if (err) { 70 | if ( err.code == "NoSuchBucket") { // No sweat, bucket doesn't exist 71 | resolve() 72 | } 73 | else { 74 | callback(err) 75 | 76 | } 77 | } 78 | else { 79 | console.log("File gone"); 80 | s3.deleteBucket({Bucket: myBucket}, function (err, data) { 81 | if (err) { 82 | callback ( err ) 83 | } else { 84 | resolve () // All good 85 | } 86 | }); 87 | 88 | } // successful response 89 | }); 90 | 91 | }); 92 | } 93 | 94 | 95 | 96 | exports.handler = (event, context, callback) => { 97 | 98 | myBucket=event.ResourceProperties['bucketname'] 99 | oktaOrg=event.ResourceProperties['oktaOrg'] 100 | 101 | if (event.RequestType == 'Create') { 102 | 103 | createS3Bucket(myBucket, callback).then(function () { 104 | createIndexFile(myBucket, "index.html").then ( function() { 105 | response.send(event, context, response.SUCCESS, {"1":"1"}); 106 | 107 | }).catch( function(err) { 108 | response.send(event, context, response.FAILED, {"1":"1"}); 109 | 110 | }) 111 | }) 112 | } 113 | 114 | else if (event.RequestType == 'Delete') { 115 | deleteS3Bucket(myBucket, callback).then(function () { 116 | response.send(event, context, response.SUCCESS, {"1":"1"}); 117 | }) 118 | } 119 | }; 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/setups3bucket/oktaLoginPage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 23 | 24 |
25 |
26 | 27 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /loginWidgetJsfiddle/readme.md: -------------------------------------------------------------------------------- 1 | # I started experimenting running the Okta Login widet with JSFiddle, this 2 | worked for me, just change your ClientID and Org. 3 | 4 | ``` 5 | 6 | 7 | 10 | 11 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 27 | 28 |
29 |
30 | 31 | 154 | 155 | 156 | 157 | `` 158 | 159 | -------------------------------------------------------------------------------- /awsSamOktaRental/vehicles/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | 3 | var inventory= { 4 | "inventory": [ 5 | { "id":"112345", "make":"Jeep", "model":"Wrangler", "class":"Offroad", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, 4x4, Removable Top, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Mirrors, Power Windows, Tilt Steering\n", "price":"35", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80jes162b021001.png" }, 6 | { "id":"122346", "make":"Ford", "model":"Explorer", "class":"SUV", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering\n", "price":"55", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80fos101a021001.png" }, 7 | { "id":"123347", "make":"Subaru", "model":"Forester", "class":"SUV", "desc":"Radio, CD, AWD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering\n", "price":"35", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70sus041f021001.png" }, 8 | { "id":"544321", "make":"Honda", "model":"Accord", "class":"Midsize", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering\n", "price":"25", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80hoc011e021001_2.png" }, 9 | { "id":"545321", "make":"Mercedes-Benz", "model":"AMG C 43", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"125", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70mbcbg5a021001.png" }, 10 | { "id":"546321", "make":"Cadillac", "model":"ATS-V", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"95", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc60cac222a021001.png" }, 11 | { "id":"547321", "make":"Chevrolet", "model":"Cruze", "class":"Midsize", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering", "price":"15", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70chc302b021001.png" }, 12 | { "id":"123845", "make":"Toyota", "model":"Tundra", "class":"Offroad", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"65", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80tot109e021001.png" }, 13 | { "id":"123946", "make":"Buick", "model":"Encore", "class":"SUV", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"45", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70bus041a021001.png" }, 14 | { "id":"123479", "make":"Audi", "model":"S3", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"72", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70auc321a021001.png" }, 15 | { "id":"543218", "make":"Toyota", "model":"Prius c", "class":"Midsize", "desc":"Hybrid, Radio, CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"45", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70toc251b021001.png" }, 16 | { "id":"754321", "make":"Volkswagen", "model":"Volkswagen Tiguan", "class":"SUV", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"75", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80vws031b021001.png" }, 17 | { "id":"654321", "make":"Bentley", "model":"Bentley Flying Spur", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"356", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/main/USC50BEC111B021001.png" }, 18 | { "id":"254321", "make":"Toyota", "model":"Camry", "class":"Midsize", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"35", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80toc021b021001.png" } 19 | ] 20 | } 21 | 22 | var response = { 23 | statusCode: 200, 24 | body: JSON.stringify(inventory), 25 | "isBase64Encoded": false 26 | }; 27 | console.log("response: " + JSON.stringify(response)) 28 | callback(null, response); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /awsOktaRentalWithAuthorizer/vehicles/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | 3 | var inventory= { 4 | "inventory": [ 5 | { "id":"112345", "make":"Jeep", "model":"Wrangler", "class":"Offroad", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, 4x4, Removable Top, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Mirrors, Power Windows, Tilt Steering\n", "price":"35", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80jes162b021001.png" }, 6 | { "id":"122346", "make":"Ford", "model":"Explorer", "class":"SUV", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering\n", "price":"55", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80fos101a021001.png" }, 7 | { "id":"123347", "make":"Subaru", "model":"Forester", "class":"SUV", "desc":"Radio, CD, AWD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering\n", "price":"35", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70sus041f021001.png" }, 8 | { "id":"544321", "make":"Honda", "model":"Accord", "class":"Midsize", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering\n", "price":"25", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80hoc011e021001_2.png" }, 9 | { "id":"545321", "make":"Mercedes-Benz", "model":"AMG C 43", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"125", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70mbcbg5a021001.png" }, 10 | { "id":"546321", "make":"Cadillac", "model":"ATS-V", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"95", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc60cac222a021001.png" }, 11 | { "id":"547321", "make":"Chevrolet", "model":"Cruze", "class":"Midsize", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering", "price":"15", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70chc302b021001.png" }, 12 | { "id":"123845", "make":"Toyota", "model":"Tundra", "class":"Offroad", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"65", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80tot109e021001.png" }, 13 | { "id":"123946", "make":"Buick", "model":"Encore", "class":"SUV", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"45", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70bus041a021001.png" }, 14 | { "id":"123479", "make":"Audi", "model":"S3", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"72", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70auc321a021001.png" }, 15 | { "id":"543218", "make":"Toyota", "model":"Prius c", "class":"Midsize", "desc":"Hybrid, Radio, CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"45", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70toc251b021001.png" }, 16 | { "id":"754321", "make":"Volkswagen", "model":"Volkswagen Tiguan", "class":"SUV", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"75", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80vws031b021001.png" }, 17 | { "id":"654321", "make":"Bentley", "model":"Bentley Flying Spur", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"356", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/main/USC50BEC111B021001.png" }, 18 | { "id":"254321", "make":"Toyota", "model":"Camry", "class":"Midsize", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"35", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80toc021b021001.png" } 19 | ] 20 | } 21 | 22 | var response = { 23 | statusCode: 200, 24 | body: JSON.stringify(inventory), 25 | "isBase64Encoded": false 26 | }; 27 | console.log("response: " + JSON.stringify(response)) 28 | callback(null, response); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /awsSam/readme.md: -------------------------------------------------------------------------------- 1 | ##### Start local API Gateway: 2 | 3 | `sam local start-api` 4 | 5 | ##### Before deployment, make bucket: (Make Bucket) 6 | 7 | `aws s3 mb s3://bucket-name` 8 | 9 | ##### Package: 10 | 11 | `sam package --template-file template.yaml --s3-bucket [your_s3_bucket] --output-template-file package.yaml` 12 | 13 | **Note, drop the s3:// prefix before packaging** *(Wasn't so obvious to me)* 14 | 15 | `sam deploy --template-file package.yaml --stack-name serverless-application --capabilities CAPABILITY_IAM` 16 | 17 | ##### To remove the stack, run the following command: 18 | 19 | `aws cloudformation delete-stack --stack-name serverless-application` 20 | 21 | ##### Nice Example of script that does it all for you: 22 | 23 | Honestly, this deployment was pretty rough to get going.. Here is a working example of what i used to deploy an API Gateway with an Authorizer. I'll show the deployment script, then the SAM Template *(Thanks Brent)* 24 | 25 | #### Sample Template 26 | 27 | ``` 28 | AWSTemplateFormatVersion: '2010-09-09' 29 | Transform: AWS::Serverless-2016-10-31 30 | Description: An example serverless "Hello World2 " application with a custom authorizer. 31 | 32 | Parameters: 33 | AutoPublishAliasName: 34 | Type: String 35 | Default: current 36 | Description: The alias used for Auto Publishing 37 | StageName: 38 | Type: String 39 | Default: prod 40 | Description: The Lambda Function and API Gateway Stage 41 | FunctionName: 42 | Type: String 43 | Default: Example 44 | Description: The Lambda Function Name 45 | 46 | Outputs: 47 | ExampleAPIUrl: 48 | Value: !Sub "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/" 49 | 50 | Resources: 51 | ApiGateway: 52 | Type: AWS::Serverless::Api 53 | Properties: 54 | StageName: Prod 55 | DefinitionBody: 56 | swagger: 2.0 57 | info: 58 | title: 59 | Ref: AWS::StackName 60 | securityDefinitions: 61 | test-authorizer: 62 | type: apiKey 63 | name: Authorization 64 | in: header 65 | x-amazon-apigateway-authtype: custom 66 | x-amazon-apigateway-authorizer: 67 | type: token 68 | authorizerUri: 69 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${TestAuthorizerFunc.Arn}/invocations 70 | authorizerResultTtlInSeconds: 5 71 | paths: 72 | "/": 73 | get: 74 | x-amazon-apigateway-integration: 75 | httpMethod: post 76 | type: aws_proxy 77 | uri: 78 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloWorld.Arn}/invocations 79 | responses: {} 80 | security: 81 | - test-authorizer: [] 82 | 83 | HelloWorld: 84 | Type: AWS::Serverless::Function 85 | Properties: 86 | Handler: lambda_function.lambda_handler 87 | Runtime: python3.6 88 | CodeUri: ./HelloWorld 89 | Events: 90 | GetApi: 91 | Type: Api 92 | Properties: 93 | Path: / 94 | Method: get 95 | RestApiId: 96 | Ref: ApiGateway 97 | 98 | TestAuthorizerFunc: 99 | Type: AWS::Serverless::Function 100 | Properties: 101 | Handler: lambda_function.lambda_handler 102 | Runtime: python3.6 103 | CodeUri: ./TestAuthorizerFunc 104 | 105 | TestAuthorizerFuncPerm: 106 | Type: AWS::Lambda::Permission 107 | DependsOn: 108 | - ApiGateway 109 | - TestAuthorizerFunc 110 | Properties: 111 | Action: lambda:InvokeFunction 112 | FunctionName: 113 | Ref: TestAuthorizerFunc 114 | Principal: apigateway.amazonaws.com 115 | 116 | ``` 117 | 118 | #### Deploy.sh (This script rocks!, I forgot who wrote it, thank you though) 119 | 120 | ``` 121 | #!/bin/bash 122 | 123 | S3_BUCKET=$1 124 | STACK_NAME=$2 125 | 126 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME" 127 | 128 | if [ -z "$S3_BUCKET" ]; then 129 | echo "Missing S3_BUCKET and STACK_NAME" 130 | echo $USE_MSG 131 | exit 1 132 | fi 133 | 134 | if [ -z "$STACK_NAME" ]; then 135 | echo "Missing STACK_NAME" 136 | echo $USE_MSG 137 | exit 1 138 | fi 139 | 140 | # zip up functionZZ 141 | #zip api-proxy-lambda.zip index.js 142 | 143 | # upload zip to S3 144 | sam package --template-file 03-sam-swagger-auth-template.yaml --s3-bucket $S3_BUCKET --output-template-file output.yaml 145 | 146 | # deploy to cloud formation 147 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM 148 | 149 | # get API endpoint 150 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 151 | 152 | # remove quotes 153 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 154 | 155 | echo "Test in browser: $API_ENDPOINT" 156 | 157 | 158 | ``` 159 | 160 | #### This is what it outputs when it is done 161 | 162 | ``` 163 | ./deploy.sh okta914 okta914 164 | A newer version of the AWS SAM CLI is available! 165 | Your version: 0.2.11 166 | Latest version: 0.3.0 167 | See https://github.com/awslabs/aws-sam-local for upgrade instructions 168 | 169 | Uploading to 5392c0189bd17e63977147a23dc64381 334 / 334.0 (100.00%) 170 | Successfully packaged artifacts and wrote output template to file output.yaml. 171 | Execute the following command to deploy the packaged template 172 | aws cloudformation deploy --template-file /private/tmp/sam4/Serverless-Hello-World/hello-world/output.yaml --stack-name 173 | A newer version of the AWS SAM CLI is available! 174 | Your version: 0.2.11 175 | Latest version: 0.3.0 176 | See https://github.com/awslabs/aws-sam-local for upgrade instructions 177 | 178 | Waiting for changeset to be created.. 179 | Waiting for stack create/update to complete 180 | Successfully created/updated stack - okta914 181 | Test in browser: https://jdi7dp6d.execute-api.us-east-1.amazonaws.com/prod/ 182 | ``` -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # My Notes 2 | 3 | I had a bunch of notes I was keeping in Google Keep, that no one else could see or use, so I decided to put many of them up on GitHub.com so maybe other could find them useful. 4 | 5 | [starterHTML](./starterHTML)
6 | When starting with HTML from Scratch, this what what I use, 7 | it has a simple style sheet and **Jquery** 8 | ready to run. 9 | 10 | [Login Widget on JsFiddle](./loginWidgetJsfiddle)
11 | I experiemented with successfully running the Okta Login Widget on JSFiddle, works great ! and perfect for training. 12 | 13 | [Login Widget with CORS on PHP Server](./loginWidgetCorsOnPhp)
14 | **CORS** configuration can be confusing when you first start, this is about as basic 15 | of an example as I could create to show how to send a Bearer Token to a Server 16 | via CORS. 17 | 18 | [Javascript Promises](./javascriptPromises)
19 | **Promises** Promises were a bit tricky for me, I used this over and over again until 20 | I felt comfortable with it. It also uses the ES5/6 **Fat Arrow** to abbreviate the functions. 21 | 22 | ### Okta 23 | 24 | [Custom Login page with SPA](./oktaMultipleLoginPage)
25 | Working with Okta On Pre 26 | 27 | [Add Key to Okta On Premise Agent/JRE](./oktaKeystore)
28 | Working with Okta On Premise Agent, and using HTTP(s), this step is required. 29 | 30 | ### AWS SAM (Server Application Model) 31 | 32 | ##### Generate test events from SAM: 33 | `sam local generate-event help` *Lists all options* 34 | 35 | [AWS Sample Templates](https://s3.amazonaws.com/cloudformation-examples-us-east-1/AWSCloudFormation-samples.zip)
36 | Lots of Sample Templates, you'll need them as a reference 37 | 38 | [Getting going with SAM](./awsSam)
39 | Example I used to get me started with AWS SAM 40 | 41 | [More Simple Examples of using SAM / Cloudformation](./awsSam2)
42 | SAM takes a while to understand, still learning, refined what I was workign with. 43 | 44 | [Okta Guest Account SAM / Cloudformation](./awsSamOktaGuest)
45 | Creates a Lambda and API Gateway to log a user in as a Guest 46 | 47 | [AWS ApiGateway, Anything goes Authorizer](./awsAnythingGoesAuthorizer)
48 | A Authorizer for Allowing/Denying Anything, for test 49 | 50 | [AWS SAM/Cloudformation for Okta Rental Backend](./awsSamOktaRental)
51 | Example of how to use SAM/Cloudformation to deploy API Gateway on Amazon AWS **Will Add Authorizer soon** 52 | 53 | [AWS SAM/Cloudformation for Okta Rental Backend w/ Authorizer](./awsOktaRentalWithAuthorizer)
54 | Combining the above two examples, API Gateway w/ an Authorizer 55 | 56 | [AWS LaunchStack and Share!](./awsLaunchStack)
57 | Now get **Fancy** create a new **[LaunchStack]** Button on your code, and share your code 58 | 59 | [Run Lambda Function in Cloudformation Template](./awsCloudformationRunLambda)
60 | Run a Lambda Function from your SAM Cloudformation Teamplate **(Hard to figure out)** 61 | 62 | [Capture output from Custom Resource](./awsCustomResourceOutput)
63 | Capture the output from a Custom Resource (lambda in this case) 64 | 65 | [Create Lambda with Role (YAML)](./awsCloudformationInlineLambdaWithRole)
66 | Create an in-line Lambda function, and configure Role 67 | 68 | [Custom Resource Orchestration](./awsCloudformationCustomResourceOrchestration)
69 | Run Custom Resource, then take output and pass to another Custom Resource 70 | 71 | [Create S3 Bucket with URL for Okta Org](./awsCloudformationMakeBucket)
72 | Create S3 Bucket, make Okta login widget page 73 | 74 | ### node.js 75 | 76 | [Random Code Snippets](./nodeRandomSnippets)
77 | Random Code snippets I use when I forget stuff 78 | 79 | [How I test my package with Docker](https://github.com/pmcdowell-okta/Dockerized-AWSCLI)
80 | This is how I use Docker to test github releases 81 | 82 | [Recursively install packages](https://github.com/emgeee/recursive-install#readme)
83 | When I have multiple directories of package (like Lambdas) I use npm-recursive-install 84 | ### Angular 85 | 86 | [Angular Notes](./angularNotes)
87 | Getting started with Angular 5-ish. Notes to get me going 88 | 89 | ### Amazon basics 90 | 91 | Switch User Profile AWS CLI: `export AWS_PROFILE=user` 92 | 93 | ### Amazon Lambda 94 | 95 | [Testing lambdas locally with lambda-local](./awsLambdaTest)
96 | How to test your lambda function locally 97 | 98 | [Amazon Upload Basic Lambda](./amazonLambdaUpload)
99 | Upload a basic Lambda Function using AWS CLI. 100 | 101 | [Amazon Misc Commands](./amazonLambdaMisc)
102 | Delete, list, and Mass Delete Lambda Functions 103 | 104 | [Stock Lambda Function](./awsLambdaStock)
105 | The Standard Lambda Function in AWS.. Sometimes I need to look it up. 106 | 107 | ### Amazon Cloud Watch 108 | 109 | [Delete All Cloudwatch Logs](./amazonDeleteCloudLogs)
110 | I use this often, even setup an Alias for it in Bash 111 | 112 | ### Amazon Lambda Edge Functions 113 | [Set Cookie on Amazon Lambda Edge](./lambdaEdgeSetCookie)
114 | Set a Cookie on Lambda Edge.. In this case I was working to exchange a cookie for a JWT. 115 | 116 | [Lambda Edge Static Web Page](./lambdaEdgeStaticWebpage)
117 | Render a Static Web Page on Lambda Edge (ideally you would use an S3 Bucket, but this will get you started) 118 | 119 | ### Amazon S3 120 | 121 | [Common S3 Commands you should know](./amazonS3CommonCommands)
122 | Common Commands you should know. *But often forget* 123 | 124 | [Delete all S3 Buckets](./amazonDeleteS3Buckets)
125 | *Use at your own Risk*, but I used this often for testing 126 | 127 | [Delete Buckets with Versioning](./awsS3DeleteBucketsWithVersioning)
128 | It's a pain deleting buckets with Versioning, this helped me. 129 | 130 | ### PHP 131 | 132 | [PHP Jwt Decode](./phpDecodeJwt)
133 | Decode JWT in php, this does not include verification code 134 | 135 | ### Docker 136 | 137 | ##### Basics 138 | 139 | **Build Docker Image** `docker build -t pmcdowell/deletemeanytimne .`
140 | **Push to DockerHub** `docker push pmcdowell/deletemeanytimne`
141 | **Docker Rename** `docker rename my_container my_new_container`
142 | **Docker force Delete Image** `docker rmi a693c8a85fa7 -f`
143 | **Quick, run a PHP Server** `docker run -p 8000:80 -it -v "$PWD":/var/www/html php:7.0-apache /bin/bash -c "service apache2 start; bash"`
144 |
145 | 146 | [Docker Snapshot](./dockerSnapshot)
147 | Simple instructions to take a snapshot in Docker 148 | 149 | [Docker Nginx Hacking Proxy](./dockerNginxHacking)
150 | Simple Reverse Proxy with Nginx using Docker 151 | 152 | [Okta Agent Dockerfile](./oktaServer)
153 | This is a Centos Docker Image I used to run Okta LDAP and On-Premise Agent 154 | 155 | ### GIT 156 | 157 | [Basic .gitignore file](./gitignore)
158 | This is the basic file I use for Git to ignore my .idea and other files. 159 | 160 | ### Security Stuff 161 | 162 | [Generate Self Signed Certificates](./securityCertificatesCreate)
163 | Script to make certificates 164 | 165 | ### Bash Shell 166 | 167 | Do a infinite For/Loop : `while true ; do echo "do this"; done 168 | 169 | Make symbolic Link : `ln -s /Users/mickeymouse/Box\ Sync/c-\=Code\=-/`
170 | Reverse looking previous coommands: `[CTRL-r]` *MacOS* *(Thanks Joël for this trick)*
171 | Goto Beginning of Line: `[CTRL-a]` *MacOS*
172 | Goto End of Line: `[CTRL-e]` *MacOS* 173 | ` 174 | ### Microsoft Remote Desktop 175 | 176 | **CTRL**+**ALT**+**DEL** = `FM+CTRL+OPTION+delete` 177 | 178 | 179 | ### Intellij / JetBrains 180 | 181 | **Increase Selected Text** `[OPTION] + [UP ARROW]`
182 | **Surround code With** `[OPTION] + [COMMAND] + t `
183 | **Join lines** `[CTRL] + [SHIFT] +j`
184 | **Select words w/ keyboard** `[Shift]+[Option] (left/right) arrow`
185 | **Vertical Selection CMD.exe style** `[Option] , drag cursor`
186 | **Multi Cursor** `[Option] + [Shift] , Click Away`
187 | 188 | -------------------------------------------------------------------------------- /loginWidgetBootstrap/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 22 | 23 | 24 |
25 |
26 |
27 | 30 |
31 |
32 |
33 |
35 |

37 | Sign In

38 |
39 |
40 |
41 |
48 |
49 |
50 |
57 |
58 |
59 |
65 |
66 |
67 |
68 |
69 |
70 | 71 | 72 |
73 |
74 | 83 |
84 |
85 |
86 |
87 | 88 |
89 | 90 | 91 | 92 | 223 | 224 | -------------------------------------------------------------------------------- /loginWidgetBootstrap/readme.md: -------------------------------------------------------------------------------- 1 | ### Bootstrap the login widget w/ Auth SDK 2 | 3 | *Sometimes*, the login widget doesn't do quite what you want, this bit of code 4 | renders some HTML that looks like the Login Widget, and then get the stateToken 5 | from an Authentication and Bootstraps the login widget, so you can handle MFA or 6 | what ever might be required. 7 | 8 | ##### In this use case, I needed to run the authentication twice, that was just 9 | junk code, but I wanted to share some sample code. 10 | 11 | ``` 12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 | 28 | 29 | 30 | 34 | 35 | 36 |
37 |
38 |
39 | 42 |
43 |
44 |
45 |
47 |

49 | Sign In

50 |
51 |
52 |
53 |
60 |
61 |
62 |
69 |
70 |
71 |
77 |
78 |
79 |
80 |
81 |
82 | 83 | 84 |
85 |
86 | 95 |
96 |
97 |
98 |
99 | 100 |
101 | 102 | 103 | 104 | 235 | 236 | 237 | 238 | ``` 239 | --------------------------------------------------------------------------------