⬆️ Upgrade passport to identity
This commit is contained in:
parent
9986fb0b9c
commit
7cecb8f8f7
@ -2,7 +2,7 @@ package models
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// Account profiles basically fetched from Hydrogen.Passport
|
// Account profiles basically fetched from Hydrogen.Identity
|
||||||
// But cache at here for better usage
|
// But cache at here for better usage
|
||||||
// At the same time this model can make relations between local models
|
// At the same time this model can make relations between local models
|
||||||
type Account struct {
|
type Account struct {
|
||||||
|
@ -16,12 +16,12 @@ var cfg oauth2.Config
|
|||||||
func buildOauth2Config() {
|
func buildOauth2Config() {
|
||||||
cfg = oauth2.Config{
|
cfg = oauth2.Config{
|
||||||
RedirectURL: fmt.Sprintf("https://%s/auth/callback", viper.GetString("domain")),
|
RedirectURL: fmt.Sprintf("https://%s/auth/callback", viper.GetString("domain")),
|
||||||
ClientID: viper.GetString("passport.client_id"),
|
ClientID: viper.GetString("identity.client_id"),
|
||||||
ClientSecret: viper.GetString("passport.client_secret"),
|
ClientSecret: viper.GetString("identity.client_secret"),
|
||||||
Scopes: []string{"openid"},
|
Scopes: []string{"openid"},
|
||||||
Endpoint: oauth2.Endpoint{
|
Endpoint: oauth2.Endpoint{
|
||||||
AuthURL: fmt.Sprintf("%s/auth/o/connect", viper.GetString("passport.endpoint")),
|
AuthURL: fmt.Sprintf("%s/auth/o/connect", viper.GetString("identity.endpoint")),
|
||||||
TokenURL: fmt.Sprintf("%s/api/auth/token", viper.GetString("passport.endpoint")),
|
TokenURL: fmt.Sprintf("%s/api/auth/token", viper.GetString("identity.endpoint")),
|
||||||
AuthStyle: oauth2.AuthStyleInParams,
|
AuthStyle: oauth2.AuthStyleInParams,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ func postLogin(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
agent := fiber.
|
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))
|
Set(fiber.HeaderAuthorization, fmt.Sprintf("Bearer %s", token.AccessToken))
|
||||||
|
|
||||||
_, body, errs := agent.Bytes()
|
_, 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))
|
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)
|
err = json.Unmarshal(body, &userinfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("failed to parse userinfo: %q", err))
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("failed to parse userinfo: %q", err))
|
||||||
|
@ -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 {
|
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{
|
agent.JSON(fiber.Map{
|
||||||
"client_id": viper.GetString("passport.client_id"),
|
"client_id": viper.GetString("identity.client_id"),
|
||||||
"client_secret": viper.GetString("passport.client_secret"),
|
"client_secret": viper.GetString("identity.client_secret"),
|
||||||
"subject": subject,
|
"subject": subject,
|
||||||
"content": content,
|
"content": content,
|
||||||
"links": links,
|
"links": links,
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PassportUserinfo struct {
|
type IdentityUserinfo struct {
|
||||||
Sub string `json:"sub"`
|
Sub string `json:"sub"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
@ -20,7 +20,7 @@ type PassportUserinfo struct {
|
|||||||
PreferredUsername string `json:"preferred_username"`
|
PreferredUsername string `json:"preferred_username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func LinkAccount(userinfo PassportUserinfo) (models.Account, error) {
|
func LinkAccount(userinfo IdentityUserinfo) (models.Account, error) {
|
||||||
id, _ := strconv.Atoi(userinfo.Sub)
|
id, _ := strconv.Atoi(userinfo.Sub)
|
||||||
|
|
||||||
var account models.Account
|
var account models.Account
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Navbar from "./shared/Navbar.tsx";
|
import Navigator from "./shared/Navigator.tsx";
|
||||||
import { readProfiles, useUserinfo } from "../stores/userinfo.tsx";
|
import { readProfiles, useUserinfo } from "../stores/userinfo.tsx";
|
||||||
import { createEffect, createMemo, createSignal, Show } from "solid-js";
|
import { createEffect, createMemo, createSignal, Show } from "solid-js";
|
||||||
import { readWellKnown } from "../stores/wellKnown.tsx";
|
import { readWellKnown } from "../stores/wellKnown.tsx";
|
||||||
@ -54,7 +54,7 @@ export default function RootLayout(props: any) {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Show when={!searchParams["embedded"]}>
|
<Show when={!searchParams["embedded"]}>
|
||||||
<Navbar />
|
<Navigator />
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
<main class={`${mainContentStyles()} scrollbar-hidden`}>{props.children}</main>
|
<main class={`${mainContentStyles()} scrollbar-hidden`}>{props.children}</main>
|
||||||
|
@ -9,7 +9,7 @@ interface MenuItem {
|
|||||||
href?: string;
|
href?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Navbar() {
|
export default function Navigator() {
|
||||||
const nav: MenuItem[] = [
|
const nav: MenuItem[] = [
|
||||||
{ icon: "fa-solid fa-pen-nib", label: "Creators", href: "/creators" },
|
{ icon: "fa-solid fa-pen-nib", label: "Creators", href: "/creators" },
|
||||||
{ icon: "fa-solid fa-newspaper", label: "Feed", href: "/" },
|
{ icon: "fa-solid fa-newspaper", label: "Feed", href: "/" },
|
@ -9,7 +9,7 @@ secret = "LtTjzAGFLshwXhN4ZD4nG5KlMv1MWcsvfv03TSZYnT1VhiAnLIZFTnHUwR0XhGgi"
|
|||||||
|
|
||||||
content = "uploads"
|
content = "uploads"
|
||||||
|
|
||||||
[passport]
|
[identity]
|
||||||
client_id = "goatplaza"
|
client_id = "goatplaza"
|
||||||
client_secret = "Z9k9AFTj^p"
|
client_secret = "Z9k9AFTj^p"
|
||||||
endpoint = "https://id.smartsheep.studio"
|
endpoint = "https://id.smartsheep.studio"
|
||||||
|
Loading…
Reference in New Issue
Block a user