Skip to content

Commit 05bafe1

Browse files
linuxdo
1 parent 707b728 commit 05bafe1

File tree

6 files changed

+95
-36
lines changed

6 files changed

+95
-36
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- linuxdo
7+
workflow_dispatch:
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: excalidraw-full-linuxdo
12+
OWNER: betterandbetterii
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
with:
25+
submodules: true
26+
27+
- name: Log in to Container Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ${{ env.REGISTRY }}
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Extract metadata
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.IMAGE_NAME }}
39+
tags: |
40+
type=ref,event=branch
41+
type=ref,event=pr
42+
type=semver,pattern={{version}}
43+
type=semver,pattern={{major}}.{{minor}}
44+
type=raw,value=latest,enable={{is_default_branch}}
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Build and push Docker image
50+
uses: docker/build-push-action@v5
51+
with:
52+
context: .
53+
file: ./excalidraw-complete.Dockerfile
54+
push: true
55+
tags: ${{ steps.meta.outputs.tags }}
56+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.IMAGE_NAME }}:buildcache
57+
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.IMAGE_NAME }}:buildcache,mode=max

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
[submodule "excalidraw"]
55
path = excalidraw
66
url = git@github.com:BetterAndBetterII/excalidraw.git
7-
branch = multi-canvas
7+
branch = multi-canvas-linuxdo

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.8'
22

33
services:
44
excalidraw:
5-
image: ghcr.io/betterandbetterii/excalidraw-full:latest
5+
image: ghcr.io/betterandbetterii/excalidraw-full-linuxdo:linuxdo
66
ports:
77
- "3002:3002"
88
volumes:

handlers/auth/github.go

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ import (
1515
"github.com/golang-jwt/jwt/v5"
1616
"github.com/sirupsen/logrus"
1717
"golang.org/x/oauth2"
18-
"golang.org/x/oauth2/github"
1918
)
2019

2120
var (
22-
githubOauthConfig *oauth2.Config
23-
jwtSecret []byte
21+
oauthConfig *oauth2.Config
22+
jwtSecret []byte
2423
)
2524

2625
const oauthStateString = "random"
@@ -34,17 +33,20 @@ type AppClaims struct {
3433
}
3534

3635
func Init() {
37-
githubOauthConfig = &oauth2.Config{
38-
ClientID: os.Getenv("GITHUB_CLIENT_ID"),
39-
ClientSecret: os.Getenv("GITHUB_CLIENT_SECRET"),
40-
RedirectURL: os.Getenv("GITHUB_REDIRECT_URL"),
36+
oauthConfig = &oauth2.Config{
37+
ClientID: os.Getenv("LINUXDO_CLIENT_ID"),
38+
ClientSecret: os.Getenv("LINUXDO_CLIENT_SECRET"),
39+
RedirectURL: os.Getenv("LINUXDO_REDIRECT_URL"),
4140
Scopes: []string{"read:user", "user:email"},
42-
Endpoint: github.Endpoint,
41+
Endpoint: oauth2.Endpoint{
42+
AuthURL: "https://connect.linux.do/oauth2/authorize",
43+
TokenURL: "https://connect.linux.do/oauth2/token",
44+
},
4345
}
4446
jwtSecret = []byte(os.Getenv("JWT_SECRET"))
4547

46-
if githubOauthConfig.ClientID == "" || githubOauthConfig.ClientSecret == "" {
47-
logrus.Warn("GitHub OAuth credentials are not set. Authentication routes will not work.")
48+
if oauthConfig.ClientID == "" || oauthConfig.ClientSecret == "" {
49+
logrus.Warn("OAuth credentials are not set. Authentication routes will not work.")
4850
}
4951
if len(jwtSecret) == 0 {
5052
logrus.Warn("JWT_SECRET is not set. Authentication routes will not work.")
@@ -65,72 +67,72 @@ func generateStateOauthCookie(w http.ResponseWriter) string {
6567
return state
6668
}
6769

68-
func HandleGitHubLogin(w http.ResponseWriter, r *http.Request) {
69-
if githubOauthConfig.ClientID == "" {
70-
http.Error(w, "GitHub OAuth is not configured", http.StatusInternalServerError)
70+
func HandleOAuthLogin(w http.ResponseWriter, r *http.Request) {
71+
if oauthConfig.ClientID == "" {
72+
http.Error(w, "OAuth is not configured", http.StatusInternalServerError)
7173
return
7274
}
7375
state := generateStateOauthCookie(w)
74-
url := githubOauthConfig.AuthCodeURL(state)
76+
url := oauthConfig.AuthCodeURL(state)
7577
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
7678
}
7779

78-
func HandleGitHubCallback(w http.ResponseWriter, r *http.Request) {
79-
if githubOauthConfig.ClientID == "" {
80-
http.Error(w, "GitHub OAuth is not configured", http.StatusInternalServerError)
80+
func HandleOAuthCallback(w http.ResponseWriter, r *http.Request) {
81+
if oauthConfig.ClientID == "" {
82+
http.Error(w, "OAuth is not configured", http.StatusInternalServerError)
8183
return
8284
}
8385

8486
oauthState, _ := r.Cookie("oauthstate")
8587
if r.FormValue("state") != oauthState.Value {
86-
logrus.Error("invalid oauth github state")
88+
logrus.Error("invalid oauth state")
8789
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
8890
return
8991
}
9092

91-
token, err := githubOauthConfig.Exchange(context.Background(), r.FormValue("code"))
93+
token, err := oauthConfig.Exchange(context.Background(), r.FormValue("code"))
9294
if err != nil {
9395
logrus.Errorf("failed to exchange token: %s", err.Error())
9496
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
9597
return
9698
}
9799

98-
client := githubOauthConfig.Client(context.Background(), token)
99-
resp, err := client.Get("https://api.github.com/user")
100+
client := oauthConfig.Client(context.Background(), token)
101+
resp, err := client.Get("https://connect.linux.do/api/user")
100102
if err != nil {
101-
logrus.Errorf("failed to get user from github: %s", err.Error())
103+
logrus.Errorf("failed to get user from oauth provider: %s", err.Error())
102104
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
103105
return
104106
}
105107
defer resp.Body.Close()
106108

107109
body, err := io.ReadAll(resp.Body)
108110
if err != nil {
109-
logrus.Errorf("failed to read github response body: %s", err.Error())
111+
logrus.Errorf("failed to read oauth provider response body: %s", err.Error())
110112
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
111113
return
112114
}
113115

114-
var githubUser struct {
116+
var oauthUser struct {
115117
ID int64 `json:"id"`
116118
Login string `json:"login"`
117119
AvatarURL string `json:"avatar_url"`
118120
Name string `json:"name"`
119121
}
120122

121-
if err := json.Unmarshal(body, &githubUser); err != nil {
122-
logrus.Errorf("failed to unmarshal github user: %s", err.Error())
123+
if err := json.Unmarshal(body, &oauthUser); err != nil {
124+
logrus.Errorf("failed to unmarshal oauth user: %s", err.Error())
123125
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
124126
return
125127
}
126128

127129
// For now we don't have a user database, so we create a user object on the fly.
128130
// In phase 3, we will save/get the user from the database here.
129131
user := &core.User{
130-
GitHubID: githubUser.ID,
131-
Login: githubUser.Login,
132-
AvatarURL: githubUser.AvatarURL,
133-
Name: githubUser.Name,
132+
GitHubID: oauthUser.ID,
133+
Login: oauthUser.Login,
134+
AvatarURL: oauthUser.AvatarURL,
135+
Name: oauthUser.Name,
134136
}
135137

136138
jwtToken, err := createJWT(user)

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ func setupRouter(store stores.Store) *chi.Mux {
161161
})
162162
})
163163

164-
r.Route("/auth/github", func(r chi.Router) {
165-
r.Get("/login", auth.HandleGitHubLogin)
166-
r.Get("/callback", auth.HandleGitHubCallback)
164+
r.Route("/auth/linuxdo", func(r chi.Router) {
165+
r.Get("/login", auth.HandleOAuthLogin)
166+
r.Get("/callback", auth.HandleOAuthCallback)
167167
})
168168

169169
return r

0 commit comments

Comments
 (0)