Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b69f704
feat: Validation
b01 Oct 18, 2025
ce5b1fd
feat: Shared Login
b01 Oct 18, 2025
fcbb55b
feat: Added Unauthorized Error
b01 Oct 18, 2025
4cdab46
fix: Return Parameters Swapped
b01 Oct 20, 2025
3355bc8
doc: Duplicate Method Doc Blocks
b01 Oct 20, 2025
4fff258
fix: Error Messages
b01 Oct 20, 2025
3981ad6
add: login/gpg Package
b01 Oct 21, 2025
6234763
chg: Move www/login/gpg to www/gpg
b01 Oct 21, 2025
3eafb63
chg: gpg Package Documentation
b01 Oct 21, 2025
117baaa
chore: Test login Package
b01 Oct 21, 2025
9d37604
feat: Backend Account Management
b01 Oct 23, 2025
b96f524
fix: Type In Error Message
b01 Oct 23, 2025
f4be3f8
chore: Refactor Log Messages
b01 Oct 23, 2025
d020163
chore: Update storage Package Messages
b01 Oct 23, 2025
885d66e
chg: Add Suffix to session Package
b01 Oct 24, 2025
a24e462
chore: Removed Test File
b01 Oct 24, 2025
1a8a557
fix: Storage Package
b01 Oct 24, 2025
43865ac
fix: Setting Context in Package storage for AWS S3
b01 Oct 24, 2025
d75f0db
rmv: GetContextWithTimeout
b01 Oct 25, 2025
22f5b9c
feat: Package backend Account & Device Management
b01 Oct 26, 2025
0ebf808
chg: Session ID uses UUID version 7
b01 Oct 26, 2025
58055db
fix: Package backend Not Setting Account
b01 Oct 26, 2025
1041a3b
rmv: Package session/sss
b01 Oct 26, 2025
b73f7d2
feat: Added Remove Functionality
b01 Oct 26, 2025
80bcfe2
chore: Cleanup Storage Package
b01 Oct 26, 2025
9fd0098
fix: Change Public Variables
b01 Oct 26, 2025
26ff970
fix: login Package
b01 Oct 26, 2025
bf0c803
add: Function To Initialize Account Executive
b01 Oct 26, 2025
b02da8c
chg: Remove Obsolete Contstant
b01 Oct 27, 2025
441e9ed
chg: Write Permissions for Local Storage
b01 Oct 27, 2025
0a8a597
chg: Package login/google
b01 Oct 27, 2025
96de9d6
refactor: Device Handling
b01 Oct 28, 2025
793154e
refactor: More Device Handling
b01 Oct 28, 2025
d71e597
chg: Upgrade sso Package
b01 Oct 28, 2025
825c99f
fix: Security Vulnerabilities and Dependency
b01 Oct 28, 2025
4aa3bd9
chore: Cleanup Code
b01 Oct 28, 2025
88a05ea
chg: Package gpg Encrypt
b01 Oct 28, 2025
0bf1b2e
chg: Login Package
b01 Oct 30, 2025
0730d65
fix: Account Registration Bug in Google Login
b01 Oct 30, 2025
4e75fd2
chg: Backend API
b01 Oct 30, 2025
915bd7d
fix: Initialize Backkend Application
b01 Oct 30, 2025
03c4739
chg: Loading GPG Key for Backend Application
b01 Oct 30, 2025
7369177
chore: Fixed Login Package Test
b01 Oct 30, 2025
3b62ca0
chg: Improve Google Callback in login Package
b01 Oct 31, 2025
ceca9c8
fix: Build Warnings for Log Handler
b01 Oct 31, 2025
1b702f2
chg: Base64 Encode Encypted Value Cookie
b01 Nov 1, 2025
dbf9cf4
chg: Rename Public Constant
b01 Nov 1, 2025
d761720
chg: Add Device When Logging in from a New Device
b01 Nov 2, 2025
d216543
chore: Fixed Unit Tests
b01 Nov 2, 2025
78480d3
feat: Template Manager Render Nested Templates
b01 Nov 11, 2025
92dd3e6
chg: Upgraded SSO package.
b01 Nov 16, 2025
968fbea
chg: Upgrade stdlib Package
b01 Nov 16, 2025
68e0600
chg: Upgraded sso Package
b01 Nov 18, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Directories
# -----------
/.idea/
/backend/tmp/
/storage/tmp/

# Files
# -----
Expand Down
6 changes: 3 additions & 3 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ const (
func Authenticate(headers map[string]string) error {
headerVal := GetHeader(headers, authHeader)
if headerVal == "" {
return fmt.Errorf(Stderr.AuthHeaderMissing)
return fmt.Errorf("%v", Stderr.AuthHeaderMissing)
}

envVal, ok := os.LookupEnv(authHeader)
if !ok {
return fmt.Errorf(Stderr.AuthCodeNotSet)
return fmt.Errorf("%v", Stderr.AuthCodeNotSet)
}

if headerVal != envVal {
return fmt.Errorf(Stderr.AuthCodeInvalid)
return fmt.Errorf("%v", Stderr.AuthCodeInvalid)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions awslambda/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func PreliminaryChecks(event *events.LambdaFunctionURLRequest) *events.LambdaFun

doIt, e1 := www.ShouldRedirect(host)
if e1 != nil {
Log.Errf(e1.Error())
Log.Errf("%v", e1.Error())
return www.Respond500().ToLambdaResponse()
}

Expand All @@ -75,7 +75,7 @@ func PreliminaryChecks(event *events.LambdaFunctionURLRequest) *events.LambdaFun
return www.Respond401().ToLambdaResponse()
}

Log.Infof(stdout.PreChecks)
Log.Infof("%v", stdout.PreChecks)

return nil
}
81 changes: 81 additions & 0 deletions backend/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package backend

import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"github.com/kohirens/www/storage"
)

type Account struct {
AppleID string `json:"apple_id"`
Email string `json:"email"`
FistName string `json:"fist_name"`
GoogleId string `json:"google_id"`
ID string `json:"id"`
LastName string `json:"last_name"`
}

type AccountManager interface {
AddWithProvider(providerID, providerName string) (*Account, error)
Lookup(id string) (*Account, error)
// Location The generated filename/key/path where the account
// should be located in storage.
Location(id string) string
}

// AccountExec Short for account executive, is an implementation of
// AccountManager.
type AccountExec struct {
store storage.Storage
}

// AddWithProvider Make a new account using an OIDC provider.
func (am *AccountExec) AddWithProvider(clientID, providerName string) (*Account, error) {
// Generate an account ID.
id, e1 := uuid.NewV7()
if e1 != nil {
return nil, fmt.Errorf(stderr.UUID, e1.Error())
}

account := &Account{
ID: id.String(), //TODO: generate a guid
}

switch providerName {
case "apple":
account.AppleID = clientID
case "google":
account.GoogleId = clientID
}

accountBytes, e2 := json.Marshal(account)
if e2 != nil {
return nil, fmt.Errorf(stderr.DecodeJSON, e2.Error())
}

if e := am.store.Save(am.Location(account.ID), accountBytes); e != nil {
return nil, e
}

return account, nil
}

func (am *AccountExec) Location(id string) string {
return fmt.Sprintf(PrefixAccounts+"/%v.json", id)
}

// Lookup Search for an account in storage.
func (am *AccountExec) Lookup(id string) (*Account, error) {
aData, e1 := am.store.Load(am.Location(id))
if e1 != nil {
return nil, &AccountNotFoundError{id}
}

account := &Account{}
if e2 := json.Unmarshal(aData, &account); e2 != nil {
return nil, fmt.Errorf(stderr.DecodeJSON, e2.Error())
}

return account, nil
}
89 changes: 89 additions & 0 deletions backend/account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package backend

import (
"github.com/kohirens/www/storage"
"testing"
)

func TestAccountExec_Lookup(t *testing.T) {
fixedStore, _ := storage.NewLocalStorage(fixtureDir)

tests := []struct {
name string
store storage.Storage
id string
wantErr bool
}{
{
"pull_account",
fixedStore,
"1234",
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
am := &AccountExec{
store: tt.store,
}
got, err := am.Lookup(tt.id)
if (err != nil) != tt.wantErr {
t.Errorf("Lookup() error = %v, wantErr %v", err, tt.wantErr)
return
}

if got.ID != tt.id {
t.Errorf("Lookup() got = %v, want %v", got, tt.id)
return
}
})
}
}

func TestAccountExec_Add(t *testing.T) {
fixedStore, _ := storage.NewLocalStorage(tmpDir)

tests := []struct {
name,
providerID,
providerName string
store storage.Storage
wantErr bool
}{
{
"add_account",
"1234",
"google",
fixedStore,
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
am := &AccountExec{
store: tt.store,
}
got, err := am.AddWithProvider(tt.providerID, tt.providerName)

if (err != nil) != tt.wantErr {
t.Errorf("Add() error = %v, wantErr %v", err, tt.wantErr)
return
}

if got.GoogleId != tt.providerID {
t.Errorf("Add() got = %v, want %v", got.GoogleId, tt.providerID)
return
}

got2, err2 := am.Lookup(got.ID)
if (err2 != nil) != tt.wantErr {
t.Errorf("Add() error = %v, wantErr %v", err2, tt.wantErr)
return
}
if got2.ID != got.ID {
t.Errorf("Add() error, newly added account could not be loaded")
return
}
})
}
}
Loading