⬆️ Upgrade passport to identity

This commit is contained in:
LittleSheep 2024-02-18 22:41:18 +08:00
parent 9986fb0b9c
commit 7cecb8f8f7
7 changed files with 16 additions and 16 deletions

View File

@ -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 {

View File

@ -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))

View File

@ -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,

View File

@ -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

View File

@ -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) {
}
>
<Show when={!searchParams["embedded"]}>
<Navbar />
<Navigator />
</Show>
<main class={`${mainContentStyles()} scrollbar-hidden`}>{props.children}</main>

View File

@ -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: "/" },

View File

@ -9,7 +9,7 @@ secret = "LtTjzAGFLshwXhN4ZD4nG5KlMv1MWcsvfv03TSZYnT1VhiAnLIZFTnHUwR0XhGgi"
content = "uploads"
[passport]
[identity]
client_id = "goatplaza"
client_secret = "Z9k9AFTj^p"
endpoint = "https://id.smartsheep.studio"