Enable CORS, fix nsec1 keys
This commit is contained in:
parent
825fed7d21
commit
48f04e48de
|
@ -0,0 +1 @@
|
||||||
|
.env
|
|
@ -1,3 +1,5 @@
|
||||||
|
import converter from 'npm:bech32-converting';
|
||||||
|
|
||||||
import { validator, z } from '@/deps.ts';
|
import { validator, z } from '@/deps.ts';
|
||||||
|
|
||||||
const createTokenSchema = z.object({
|
const createTokenSchema = z.object({
|
||||||
|
@ -8,8 +10,11 @@ const createTokenController = validator('json', (value, c) => {
|
||||||
const result = createTokenSchema.safeParse(value);
|
const result = createTokenSchema.safeParse(value);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
const password = result.data.password;
|
||||||
|
const token = password.startsWith('nsec1') ? converter('nsec').toHex(password).slice(2) : password;
|
||||||
|
|
||||||
return c.json({
|
return c.json({
|
||||||
access_token: result.data.password,
|
access_token: token,
|
||||||
token_type: 'Bearer',
|
token_type: 'Bearer',
|
||||||
scope: 'read write follow push',
|
scope: 'read write follow push',
|
||||||
created_at: Math.floor(new Date().getTime() / 1000),
|
created_at: Math.floor(new Date().getTime() / 1000),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Hono } from '@/deps.ts';
|
import { cors, Hono } from '@/deps.ts';
|
||||||
|
|
||||||
import { credentialsController } from './api/accounts.ts';
|
import { credentialsController } from './api/accounts.ts';
|
||||||
import { appCredentialsController, createAppController } from './api/apps.ts';
|
import { appCredentialsController, createAppController } from './api/apps.ts';
|
||||||
|
@ -8,6 +8,8 @@ import { createTokenController } from './api/oauth.ts';
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
|
app.use('/*', cors());
|
||||||
|
|
||||||
app.get('/api/v1/instance', instanceController);
|
app.get('/api/v1/instance', instanceController);
|
||||||
|
|
||||||
app.get('/api/v1/apps/verify_credentials', appCredentialsController);
|
app.get('/api/v1/apps/verify_credentials', appCredentialsController);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Context, Hono, validator } from 'https://deno.land/x/hono@v3.0.2/mod.ts';
|
import { Context, Hono, validator } from 'https://deno.land/x/hono@v3.0.2/mod.ts';
|
||||||
export { Hono, validator };
|
export { Hono, validator };
|
||||||
|
export { cors } from 'https://deno.land/x/hono@v3.0.2/middleware.ts';
|
||||||
export { z } from 'https://deno.land/x/zod@v3.20.5/mod.ts';
|
export { z } from 'https://deno.land/x/zod@v3.20.5/mod.ts';
|
||||||
export { Author, RelayPool } from 'https://dev.jspm.io/nostr-relaypool@0.5.3';
|
export { Author, RelayPool } from 'https://dev.jspm.io/nostr-relaypool@0.5.3';
|
||||||
export { getPublicKey } from 'https://dev.jspm.io/nostr-tools@1.6.0';
|
export { getPublicKey } from 'https://dev.jspm.io/nostr-tools@1.6.0';
|
||||||
|
|
Loading…
Reference in New Issue