Skip to content

Commit 7446f5a

Browse files
author
Frank
committed
wip gateway
1 parent 81a3e02 commit 7446f5a

7 files changed

Lines changed: 75 additions & 89 deletions

File tree

cloud/function/src/auth.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { Resource } from "sst"
22
import { z } from "zod"
33
import { issuer } from "@openauthjs/openauth"
44
import { createSubjects } from "@openauthjs/openauth/subject"
5+
import { CodeProvider } from "@openauthjs/openauth/provider/code"
56
import { GithubProvider } from "@openauthjs/openauth/provider/github"
7+
import { GoogleOidcProvider } from "@openauthjs/openauth/provider/google"
68
import { CloudflareStorage } from "@openauthjs/openauth/storage/cloudflare"
79
import { Account } from "@opencode/cloud-core/account.js"
810

@@ -30,6 +32,53 @@ export default {
3032
clientSecret: Resource.GITHUB_CLIENT_SECRET_CONSOLE.value,
3133
scopes: ["read:user", "user:email"],
3234
}),
35+
google: GoogleOidcProvider({
36+
clientID: Resource.GOOGLE_CLIENT_ID.value,
37+
scopes: ["openid", "email"],
38+
}),
39+
// email: CodeProvider({
40+
// async request(req, state, form, error) {
41+
// console.log(state)
42+
// const params = new URLSearchParams()
43+
// if (error) {
44+
// params.set("error", error.type)
45+
// }
46+
// if (state.type === "start") {
47+
// return Response.redirect(process.env.AUTH_FRONTEND_URL + "/auth/email?" + params.toString(), 302)
48+
// }
49+
//
50+
// if (state.type === "code") {
51+
// return Response.redirect(process.env.AUTH_FRONTEND_URL + "/auth/code?" + params.toString(), 302)
52+
// }
53+
//
54+
// return new Response("ok")
55+
// },
56+
// async sendCode(claims, code) {
57+
// const email = z.string().email().parse(claims.email)
58+
// const cmd = new SendEmailCommand({
59+
// Destination: {
60+
// ToAddresses: [email],
61+
// },
62+
// FromEmailAddress: `SST <auth@${Resource.Email.sender}>`,
63+
// Content: {
64+
// Simple: {
65+
// Body: {
66+
// Html: {
67+
// Data: `Your pin code is <strong>${code}</strong>`,
68+
// },
69+
// Text: {
70+
// Data: `Your pin code is ${code}`,
71+
// },
72+
// },
73+
// Subject: {
74+
// Data: "SST Console Pin Code: " + code,
75+
// },
76+
// },
77+
// },
78+
// })
79+
// await ses.send(cmd)
80+
// },
81+
// }),
3382
},
3483
storage: CloudflareStorage({
3584
namespace: env.AuthStorage,
@@ -50,7 +99,14 @@ export default {
5099
})
51100
const user = (await userResponse.json()) as { email: string }
52101
email = user.email
53-
} else throw new Error("Unsupported provider")
102+
} else if (response.provider === "google") {
103+
if (!response.id.email_verified) throw new Error("Google email not verified")
104+
email = response.id.email as string
105+
}
106+
//if (response.provider === "email") {
107+
// email = response.claims.email
108+
//}
109+
else throw new Error("Unsupported provider")
54110

55111
if (!email) throw new Error("No email found")
56112

cloud/function/sst-env.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ declare module "sst" {
5050
"type": "sst.sst.Secret"
5151
"value": string
5252
}
53+
"GOOGLE_CLIENT_ID": {
54+
"type": "sst.sst.Secret"
55+
"value": string
56+
}
5357
"OPENAI_API_KEY": {
5458
"type": "sst.sst.Secret"
5559
"value": string

cloud/web/src/pages/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ export default function Index() {
2424
</section>
2525

2626
<section data-slot="cta">
27-
<div data-slot="col-2">
27+
<div>
2828
<span onClick={() => auth.authorize({ provider: "github" })}>Sign in with GitHub</span>
2929
</div>
30+
<div>
31+
<span onClick={() => auth.authorize({ provider: "google" })}>Sign in with Google</span>
32+
</div>
3033
</section>
3134
</div>
3235
</div>

cloud/web/src/pages/lander.module.css

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -80,90 +80,4 @@
8080
border-left: 2px solid var(--color-border);
8181
}
8282
}
83-
84-
[data-slot="images"] {
85-
display: flex;
86-
flex-direction: row;
87-
align-items: stretch;
88-
justify-content: space-between;
89-
border-top: 2px solid var(--color-border);
90-
91-
& > div {
92-
flex: 1;
93-
display: flex;
94-
flex-direction: column;
95-
gap: calc(var(--padding) / 4);
96-
padding: calc(var(--padding) / 2);
97-
border-width: 0;
98-
border-style: solid;
99-
border-color: var(--color-border);
100-
101-
& > div, a {
102-
flex: 1;
103-
display: flex;
104-
align-items: center;
105-
}
106-
}
107-
108-
p {
109-
letter-spacing: -0.03125rem;
110-
text-transform: uppercase;
111-
color: var(--color-text-dimmed);
112-
}
113-
114-
& > div + div {
115-
border-width: 0 0 0 2px;
116-
}
117-
118-
@media (max-width: 30rem) {
119-
& {
120-
flex-direction: column;
121-
}
122-
& > div + div {
123-
border-width: 2px 0 0 0;
124-
}
125-
}
126-
}
127-
128-
[data-slot="content"] {
129-
border-top: 2px solid var(--color-border);
130-
padding: var(--padding);
131-
132-
& > p {
133-
line-height: var(--font-line-height);
134-
}
135-
136-
ol {
137-
margin-top: calc(var(--vertical-padding) / 2);
138-
padding-left: 2.5rem;
139-
list-style-type: decimal;
140-
line-height: var(--font-line-height);
141-
142-
& > li + li {
143-
margin-top: calc(var(--vertical-padding) / 2);
144-
}
145-
146-
& > li b {
147-
text-transform: uppercase;
148-
}
149-
}
150-
151-
}
152-
153-
[data-slot="footer"] {
154-
border-top: 2px solid var(--color-border);
155-
display: flex;
156-
flex-direction: row;
157-
158-
& > div {
159-
flex: 1;
160-
text-align: center;
161-
text-transform: uppercase;
162-
padding: calc(var(--padding) / 2) 0.5rem;
163-
}
164-
165-
& > div + div {
166-
border-left: 2px solid var(--color-border);
167-
}
168-
}
16983
}

infra/cloud.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ new sst.x.DevCommand("Studio", {
5656

5757
const GITHUB_CLIENT_ID_CONSOLE = new sst.Secret("GITHUB_CLIENT_ID_CONSOLE")
5858
const GITHUB_CLIENT_SECRET_CONSOLE = new sst.Secret("GITHUB_CLIENT_SECRET_CONSOLE")
59+
const GOOGLE_CLIENT_ID = new sst.Secret("GOOGLE_CLIENT_ID")
5960
const authStorage = new sst.cloudflare.Kv("AuthStorage")
6061
export const auth = new sst.cloudflare.Worker("AuthApi", {
6162
domain: `auth.${domain}`,
6263
handler: "cloud/function/src/auth.ts",
6364
url: true,
64-
link: [database, authStorage, GITHUB_CLIENT_ID_CONSOLE, GITHUB_CLIENT_SECRET_CONSOLE],
65+
link: [database, authStorage, GITHUB_CLIENT_ID_CONSOLE, GITHUB_CLIENT_SECRET_CONSOLE, GOOGLE_CLIENT_ID],
6566
})
6667

6768
const ANTHROPIC_API_KEY = new sst.Secret("ANTHROPIC_API_KEY")

packages/function/sst-env.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ declare module "sst" {
5050
"type": "sst.sst.Secret"
5151
"value": string
5252
}
53+
"GOOGLE_CLIENT_ID": {
54+
"type": "sst.sst.Secret"
55+
"value": string
56+
}
5357
"OPENAI_API_KEY": {
5458
"type": "sst.sst.Secret"
5559
"value": string

sst-env.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ declare module "sst" {
6363
"type": "sst.sst.Secret"
6464
"value": string
6565
}
66+
"GOOGLE_CLIENT_ID": {
67+
"type": "sst.sst.Secret"
68+
"value": string
69+
}
6670
"GatewayApi": {
6771
"type": "sst.cloudflare.Worker"
6872
"url": string

0 commit comments

Comments
 (0)