Skip to content

Instantly share code, notes, and snippets.

View praveen001's full-sized avatar
🎯
Focusing

Praveen Raj praveen001

🎯
Focusing
View GitHub Profile
@praveen001
praveen001 / index.html
Created March 28, 2020 21:15
Multiple themes using css variables
<!DOCTYPE html>
<html>
<style>
.default {
--primary-color: #f00;
--secondary-color: #000;
--background-default: #efefef;
--background-paper: #fff;
}
.dark {
import Collapse from '@material-ui/core/Collapse';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import IconButton from '@material-ui/core/IconButton';
import { createStyles, withStyles, WithStyles } from '@material-ui/core/styles';
import DownArrow from '@material-ui/icons/KeyboardArrowDown';
import UpArrow from '@material-ui/icons/KeyboardArrowUp';
import produce from 'immer';
import React from 'react';
import LegoCheckbox from '../Checkbox/Checkbox';
@praveen001
praveen001 / structs.go
Created January 26, 2020 14:32
Serverless WebSockets with API Gateway and Golang Lambda
// APIGatewayWebsocketProxyRequest contains data coming from the API Gateway proxy
type APIGatewayWebsocketProxyRequest struct {
MethodArn string `json:"methodArn"`
Resource string `json:"resource"` // The resource path defined in API Gateway
Path string `json:"path"` // The url path for the caller
HTTPMethod string `json:"httpMethod"`
Headers map[string]string `json:"headers"`
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
QueryStringParameters map[string]string `json:"queryStringParameters"`
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"`
@praveen001
praveen001 / message.go
Last active May 7, 2023 04:08
Serverless WebSockets with API Gateway and Golang Lambda
type MessageAction struct {
Type string `json:"type"`
Payload MessagePayload `json:"payload"`
}
// MessagePayload ..
type MessagePayload struct {
Message MessageWithInfo `json:"message"`
}
@praveen001
praveen001 / main.go
Last active January 26, 2020 14:38
Serverless WebSockets with API Gateway and Golang Lambda
// Handler is the base handler that will receive all web socket request
func Handler(request APIGatewayWebsocketProxyRequest) (interface{}, error) {
switch request.RequestContext.RouteKey {
case "$connect":
return Connect(request)
case "$disconnect":
return Disconnect(request)
default:
return Default(request)
}
@praveen001
praveen001 / disconnect.go
Last active January 26, 2020 14:40
Serverless WebSockets with API Gateway and Golang Lambda
// Disconnect will receive the $disconnect requests
func Disconnect(request APIGatewayWebsocketProxyRequest) (interface{}, error) {
id := request.RequestContext.Authorizer.(map[string]interface{})["cognito:username"].(string)
connectionID := request.RequestContext.ConnectionID
RemoveSocket(id, connectionID)
return events.APIGatewayProxyResponse{
StatusCode: 200,
}, nil
}
@praveen001
praveen001 / connect.go
Last active January 26, 2020 14:40
Serverless WebSockets with API Gateway and Golang Lambda
// Connect will receive the $connect request
// It will handle the authorization also
func Connect(request APIGatewayWebsocketProxyRequest) (interface{}, error) {
if request.RequestContext.Authorizer == nil {
return Authorizer(request)
}
id := request.RequestContext.Authorizer.(map[string]interface{})["cognito:username"].(string)
connectionID := request.RequestContext.ConnectionID
StoreSocket(id, connectionID)
@praveen001
praveen001 / authorizer.go
Last active January 26, 2020 14:38
Serverless WebSockets with API Gateway and Golang Lambda
// Authorizer custom api authorizer
func Authorizer(request APIGatewayWebsocketProxyRequest) (events.APIGatewayCustomAuthorizerResponse, error) {
token := request.QueryStringParameters["token"]
// Fetch all keys
jwkSet, err := jwk.Fetch("https://cognito-idp.us-east-1.amazonaws.com/us-east-1_vvx4f42sK/.well-known/jwks.json")
if err != nil {
log.Fatalln("Unable to fetch keys")
}
@praveen001
praveen001 / authorizer.go
Last active January 26, 2020 13:48
Serverless WebSockets with API Gateway and Golang Lambda
// Authorizer custom api authorizer
func Authorizer(request APIGatewayWebsocketProxyRequest) (events.APIGatewayCustomAuthorizerResponse, error) {
token := request.QueryStringParameters["token"]
// Fetch all keys
jwkSet, err := jwk.Fetch("https://cognito-idp.ap-south-1.amazonaws.com/ap-south-1_vvx4f42sK/.well-known/jwks.json")
if err != nil {
log.Fatalln("Unable to fetch keys")
}
@praveen001
praveen001 / aws-amplify-configure.js
Last active August 12, 2023 07:49
Passwordless Phone number authentication using AWS Amplify and Cognito
import Amplify, { Auth } from 'aws-amplify';
Amplify.configure({
Auth: {
region: 'us-east-1',
userPoolId: '**********',
userPoolWebClientId: '******************',
}
});