Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
PeanutBrrutter committed Jun 24, 2024
2 parents 5509e25 + 5f2fb0a commit 1abf9ad
Show file tree
Hide file tree
Showing 17 changed files with 731 additions and 199 deletions.
32 changes: 25 additions & 7 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
pull_request:
branches: [main]

env:
DATABASE_URL: ${{secrets.DATABASE_URL}}
# FIREBASE_ADMIN_PASSPHRASE: ${{secrets.FIREBASE_ADMIN_PASSPHRASE}}

jobs:
example:
name: Create Ubuntu OS
Expand All @@ -27,6 +31,20 @@ jobs:
go mod tidy
go get github.com/franela/goblin
ls
# - name: Setup Firebase JSON file
# run: echo "{${{ secrets.FIREBASE_JSON }}}" > edusync-7bd5e-firebase-adminsdk-x49uh-af084a6314.json

# - name: Build and run JSON validator
# run: |
# go run json_validator.go edusync-7bd5e-firebase-adminsdk-x49uh-af084a6314.json

- name: Decrypt Firebase JSON
run: |
chmod +x decrypt_secret.sh
./decrypt_secret.sh
env:
FIREBASE_ADMIN_PASSPHRASE: ${{secrets.FIREBASE_ADMIN_PASSPHRASE}}

- name: Go Test
run: |
Expand All @@ -36,30 +54,30 @@ jobs:
name: Success Message (Discord)
uses: discord-actions/message@v2
with:
webhookUrl: https://discord.com/api/webhooks/1237964301201965127/ZYe3gYTeweYEfA_Q0I-JWFVXA2dVMp7Pw7jeNNd2UlFCtvIS8ZvIN_CRQ-gUwSgl7eD2
webhookUrl: ${{secrets.DISCORD_WEBHOOK}}
message: SUCCESSFULLLL in branch ${{github.ref}} by ${{github.actor}}

- if: ${{success()}}
name: Success Message (Telegram)
uses: akeylimepie/[email protected]
with:
token: 6795256205:AAHm19-9zOM4jMtEtVOSDGExXAtg5J67rKc
chat_id: -4244340354
token: ${{secrets.TELEGRAM_TOKEN}}
chat_id: ${{secrets.TELEGRAM_CHAT_ID}}
text: SUCCESSFULLLL in branch ${{github.ref}} by ${{github.actor}}

- if: ${{failure()}}
name: Failure Message (Discord)
uses: discord-actions/message@v2
with:
webhookUrl: https://discord.com/api/webhooks/1237964301201965127/ZYe3gYTeweYEfA_Q0I-JWFVXA2dVMp7Pw7jeNNd2UlFCtvIS8ZvIN_CRQ-gUwSgl7eD2
webhookUrl: ${{secrets.DISCORD_WEBHOOK}}
message: FAILUREEEE in branch ${{github.ref}} by ${{github.actor}}

- if: ${{failure()}}
name: Failure Message (Telegram)
uses: akeylimepie/[email protected]
with:
token: 6795256205:AAHm19-9zOM4jMtEtVOSDGExXAtg5J67rKc
chat_id: -4244340354
token: ${{secrets.TELEGRAM_TOKEN}}
chat_id: ${{secrets.TELEGRAM_CHAT_ID}}
text: FAILUREEEE in branch ${{github.ref}} by ${{github.actor}}

#- name: Setup Python
Expand All @@ -73,4 +91,4 @@ jobs:
#python --version
#ls
#pip3 install pandas


6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
*.crt
*.key
*.pem
edusync-firebase.json
.env
edusync-7bd5e-firebase-adminsdk-x49uh-af084a6314.json
edusync-test-firebase-adminsdk-hk5kl-9af0162b09.json
.env
config.json
Binary file modified EduSync.exe
Binary file not shown.
50 changes: 50 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"fmt"
"html/template"
"net/http"

"github.com/gorilla/pat"
"github.com/gorilla/sessions"
"github.com/markbates/goth"
"github.com/markbates/goth/gothic"
"github.com/markbates/goth/providers/google"
)

// AuthHandler sets up the authentication routes on the provided router
func AuthHandler(router *pat.Router, config *Config) {
maxAge := 86400 * 30 // 30 days
isProd := true // Set to true when serving over https

store := sessions.NewCookieStore([]byte(config.SessionSecret))
store.MaxAge(maxAge)
store.Options.Path = "/"
store.Options.HttpOnly = true // HttpOnly should always be enabled
store.Options.Secure = isProd

gothic.Store = store

goth.UseProviders(
google.New(config.GoogleClientID, config.GoogleClientSecret, "https://localhost:8080/auth/google/callback", "email", "profile"),
)

router.Get("/auth/{provider}/callback", func(res http.ResponseWriter, req *http.Request) {
user, err := gothic.CompleteUserAuth(res, req)
if err != nil {
fmt.Fprintln(res, err)
return
}
t, _ := template.ParseFiles("templates/success.html")
t.Execute(res, user)
})

router.Get("/auth/{provider}", func(res http.ResponseWriter, req *http.Request) {
gothic.BeginAuthHandler(res, req)
})

router.Get("/", func(res http.ResponseWriter, req *http.Request) {
t, _ := template.ParseFiles("templates/index.html")
t.Execute(res, false)
})
}
32 changes: 32 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"encoding/json"
"fmt"
"os"
)

// Config struct to hold the configuration
type Config struct {
GoogleClientID string `json:"google_client_id"`
GoogleClientSecret string `json:"google_client_secret"`
SessionSecret string `json:"session_secret"`
}

// LoadConfig reads the configuration from a file
func LoadConfig(file string) (*Config, error) {
var config Config
configFile, err := os.Open(file)
if err != nil {
return nil, fmt.Errorf("cannot open config file: %w", err)
}
defer configFile.Close()

decoder := json.NewDecoder(configFile)
err = decoder.Decode(&config)
if err != nil {
return nil, fmt.Errorf("cannot decode config JSON: %w", err)
}

return &config, nil
}
Loading

0 comments on commit 1abf9ad

Please sign in to comment.