From 7cecb8f8f7caa5695466856b3f9de6558fd2e17f Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 18 Feb 2024 22:41:18 +0800 Subject: [PATCH] :arrow_up: Upgrade passport to identity --- pkg/models/accounts.go | 2 +- pkg/server/auth_api.go | 12 ++++++------ pkg/services/accounts.go | 6 +++--- pkg/services/auth.go | 4 ++-- pkg/view/src/layouts/RootLayout.tsx | 4 ++-- .../src/layouts/shared/{Navbar.tsx => Navigator.tsx} | 2 +- settings.toml | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) rename pkg/view/src/layouts/shared/{Navbar.tsx => Navigator.tsx} (98%) diff --git a/pkg/models/accounts.go b/pkg/models/accounts.go index 9e7a889..3586de8 100644 --- a/pkg/models/accounts.go +++ b/pkg/models/accounts.go @@ -2,7 +2,7 @@ package models import "time" -// Account profiles basically fetched from Hydrogen.Passport +// Account profiles basically fetched from Hydrogen.Identity // But cache at here for better usage // At the same time this model can make relations between local models type Account struct { diff --git a/pkg/server/auth_api.go b/pkg/server/auth_api.go index 1289aa2..2a84dcb 100644 --- a/pkg/server/auth_api.go +++ b/pkg/server/auth_api.go @@ -16,12 +16,12 @@ var cfg oauth2.Config func buildOauth2Config() { cfg = oauth2.Config{ RedirectURL: fmt.Sprintf("https://%s/auth/callback", viper.GetString("domain")), - ClientID: viper.GetString("passport.client_id"), - ClientSecret: viper.GetString("passport.client_secret"), + ClientID: viper.GetString("identity.client_id"), + ClientSecret: viper.GetString("identity.client_secret"), Scopes: []string{"openid"}, Endpoint: oauth2.Endpoint{ - AuthURL: fmt.Sprintf("%s/auth/o/connect", viper.GetString("passport.endpoint")), - TokenURL: fmt.Sprintf("%s/api/auth/token", viper.GetString("passport.endpoint")), + AuthURL: fmt.Sprintf("%s/auth/o/connect", viper.GetString("identity.endpoint")), + TokenURL: fmt.Sprintf("%s/api/auth/token", viper.GetString("identity.endpoint")), AuthStyle: oauth2.AuthStyleInParams, }, } @@ -46,7 +46,7 @@ func postLogin(c *fiber.Ctx) error { } agent := fiber. - Get(fmt.Sprintf("%s/api/users/me", viper.GetString("passport.endpoint"))). + Get(fmt.Sprintf("%s/api/users/me", viper.GetString("identity.endpoint"))). Set(fiber.HeaderAuthorization, fmt.Sprintf("Bearer %s", token.AccessToken)) _, body, errs := agent.Bytes() @@ -54,7 +54,7 @@ func postLogin(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("failed to get userinfo: %q", errs)) } - var userinfo services.PassportUserinfo + var userinfo services.IdentityUserinfo err = json.Unmarshal(body, &userinfo) if err != nil { return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("failed to parse userinfo: %q", err)) diff --git a/pkg/services/accounts.go b/pkg/services/accounts.go index 7a4dd54..cec5eba 100644 --- a/pkg/services/accounts.go +++ b/pkg/services/accounts.go @@ -33,10 +33,10 @@ func GetAccountFollowed(user models.Account, target models.Account) (models.Acco } func NotifyAccount(user models.Account, subject, content string, links ...fiber.Map) error { - agent := fiber.Post(viper.GetString("passport.endpoint") + "/api/dev/notify") + agent := fiber.Post(viper.GetString("identity.endpoint") + "/api/dev/notify") agent.JSON(fiber.Map{ - "client_id": viper.GetString("passport.client_id"), - "client_secret": viper.GetString("passport.client_secret"), + "client_id": viper.GetString("identity.client_id"), + "client_secret": viper.GetString("identity.client_secret"), "subject": subject, "content": content, "links": links, diff --git a/pkg/services/auth.go b/pkg/services/auth.go index 9fcd326..d2cfb28 100644 --- a/pkg/services/auth.go +++ b/pkg/services/auth.go @@ -12,7 +12,7 @@ import ( "time" ) -type PassportUserinfo struct { +type IdentityUserinfo struct { Sub string `json:"sub"` Name string `json:"name"` Email string `json:"email"` @@ -20,7 +20,7 @@ type PassportUserinfo struct { PreferredUsername string `json:"preferred_username"` } -func LinkAccount(userinfo PassportUserinfo) (models.Account, error) { +func LinkAccount(userinfo IdentityUserinfo) (models.Account, error) { id, _ := strconv.Atoi(userinfo.Sub) var account models.Account diff --git a/pkg/view/src/layouts/RootLayout.tsx b/pkg/view/src/layouts/RootLayout.tsx index aabec0a..0671270 100644 --- a/pkg/view/src/layouts/RootLayout.tsx +++ b/pkg/view/src/layouts/RootLayout.tsx @@ -1,4 +1,4 @@ -import Navbar from "./shared/Navbar.tsx"; +import Navigator from "./shared/Navigator.tsx"; import { readProfiles, useUserinfo } from "../stores/userinfo.tsx"; import { createEffect, createMemo, createSignal, Show } from "solid-js"; import { readWellKnown } from "../stores/wellKnown.tsx"; @@ -54,7 +54,7 @@ export default function RootLayout(props: any) { } > - +
{props.children}
diff --git a/pkg/view/src/layouts/shared/Navbar.tsx b/pkg/view/src/layouts/shared/Navigator.tsx similarity index 98% rename from pkg/view/src/layouts/shared/Navbar.tsx rename to pkg/view/src/layouts/shared/Navigator.tsx index 49bdc6c..74801d6 100644 --- a/pkg/view/src/layouts/shared/Navbar.tsx +++ b/pkg/view/src/layouts/shared/Navigator.tsx @@ -9,7 +9,7 @@ interface MenuItem { href?: string; } -export default function Navbar() { +export default function Navigator() { const nav: MenuItem[] = [ { icon: "fa-solid fa-pen-nib", label: "Creators", href: "/creators" }, { icon: "fa-solid fa-newspaper", label: "Feed", href: "/" }, diff --git a/settings.toml b/settings.toml index b7511b4..b84e8f5 100644 --- a/settings.toml +++ b/settings.toml @@ -9,7 +9,7 @@ secret = "LtTjzAGFLshwXhN4ZD4nG5KlMv1MWcsvfv03TSZYnT1VhiAnLIZFTnHUwR0XhGgi" content = "uploads" -[passport] +[identity] client_id = "goatplaza" client_secret = "Z9k9AFTj^p" endpoint = "https://id.smartsheep.studio"