Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions functions/auth-steam/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"context"
"fmt"
"log"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/yohcop/openid-go"
)

func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
fmt.Println("This message will show up in the CLI console!")

url, err := openid.RedirectURL(
"http://steamcommunity.com/openid",
"http://localhost:8888/.netlify/functions/steam-callback",
"http:/localhost:8888/",
)
fmt.Printf("%s", url)

if err != nil {
log.Printf("Error creating redirect URL: %q\n", err)
}
fmt.Println("Redirecting")
return &events.APIGatewayProxyResponse{
StatusCode: 302,
Headers: map[string]string{
"location": url,
"cache-control": "private",
"Access-Control-Allow-Origin": "*",
},
}, nil
}

func main() {
lambda.Start(handler)
}
39 changes: 39 additions & 0 deletions functions/steam-auth/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"context"
"fmt"
"log"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/yohcop/openid-go"
)

func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
fmt.Println("This message will show up in the CLI console.")

url, err := openid.RedirectURL(
"http://steamcommunity.com/openid",
"http://localhost:8888/.netlify/functions/steam-callback",
"http:/localhost:8888/",
)
fmt.Printf("%s", url)

if err != nil {
log.Printf("Error creating redirect URL: %q\n", err)
}
fmt.Println("Redirecting")
return &events.APIGatewayProxyResponse{
StatusCode: 302,
Headers: map[string]string{
"location": url,
"cache-control": "private",
"Access-Control-Allow-Origin": "*",
},
}, nil
}

func main() {
lambda.Start(handler)
}
61 changes: 61 additions & 0 deletions functions/steam-callback/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"context"
"fmt"
"log"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/yohcop/openid-go"
)

const (
LOGIN_ENDPOINT = "https://steamcommunity/openid/login"
OPEN_ID_MODE = "checkid_setup"
OPENIDNS = "http://specs.openid.net/auth/2.0"
OPENIDIDENTIFIER = "http://specs.openid.net/auth/2.0/identifier_select"
)

// NoOpDiscoveryCache implements the DiscoveryCache interface and doesn't cache anything.
// For a simple website, I'm not sure you need a cache.
type NoOpDiscoveryCache struct{}

// Put is a no op.
func (n *NoOpDiscoveryCache) Put(id string, info openid.DiscoveredInfo) {}

// Get always returns nil.
func (n *NoOpDiscoveryCache) Get(id string) openid.DiscoveredInfo {
return nil
}

var nonceStore = openid.NewSimpleNonceStore()
var discoveryCache = &NoOpDiscoveryCache{}

func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
fmt.Println("This message will show up in the CLI console.")
fullURL := "http://localhost:8888/.netlify/functions/steam-callback"

id, err := openid.Verify(fullURL, discoveryCache, nonceStore)
data := make(map[string]string)
fmt.Printf("%s", data["user"])
if err != nil {
log.Printf("Error verifying: %q\n", err)
} else {
log.Printf("NonceStore: %+v\n", nonceStore)
data["user"] = id
}
return &events.APIGatewayProxyResponse{
StatusCode: 200,
Headers: map[string]string{
"Content-Type": "text/plain",
"Access-Control-Allow-Origin": "*",
},
Body: string(data["user"]),
IsBase64Encoded: false,
}, nil
}

func main() {
lambda.Start(handler)
}
4 changes: 0 additions & 4 deletions functions/unlocked-achievements/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*event
dc := DisplayComponent{}

for _, v := range recentGames.Response.Games {
fmt.Printf("Name: %s\n", v.Name)
fmt.Printf("appid: %d\n", v.AppId)
aC := getGameAchievements(v.AppId)
fmt.Printf("Unlocked %d\n", len(aC))
game := Game{
Title: v.Name,
UnlockedAchivements: aC,
Expand Down Expand Up @@ -75,7 +72,6 @@ func getGameAchievements(appId int) []UnlockedAchivement {

// Get the player's achievements for a specific game
playerData := makeSteamRequest(params, ACHIEVEMENT_API)
fmt.Printf("%v", string(playerData))
playerView := PlayerAchievements{}
err := json.Unmarshal(playerData, &playerView)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ module github.com/drinkingandcoding/trophy-case

go 1.16

require github.com/aws/aws-lambda-go v1.28.0
require (
github.com/aws/aws-lambda-go v1.28.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/gorilla/pat v1.0.1 // indirect
github.com/markbates/goth v1.69.0 // indirect
github.com/yohcop/openid-go v1.0.0 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
)
Loading