Add a getClientConnectUri function, add "Nostr Connect" link in the OAuth form
This commit is contained in:
parent
bdfa6f8826
commit
3b0739f187
|
@ -2,10 +2,11 @@ import { encodeBase64 } from '@std/encoding/base64';
|
|||
import { nip19 } from 'nostr-tools';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { lodash } from '@/deps.ts';
|
||||
import { AppController } from '@/app.ts';
|
||||
import { lodash } from '@/deps.ts';
|
||||
import { nostrNow } from '@/utils.ts';
|
||||
import { parseBody } from '@/utils/api.ts';
|
||||
import { getClientConnectUri } from '@/utils/connect.ts';
|
||||
|
||||
const passwordGrantSchema = z.object({
|
||||
grant_type: z.literal('password'),
|
||||
|
@ -68,6 +69,7 @@ const oauthController: AppController = async (c) => {
|
|||
}
|
||||
|
||||
const redirectUri = maybeDecodeUri(encodedUri);
|
||||
const connectUri = await getClientConnectUri(c.req.raw.signal);
|
||||
|
||||
const script = `
|
||||
window.addEventListener('load', function() {
|
||||
|
@ -101,6 +103,8 @@ const oauthController: AppController = async (c) => {
|
|||
<input type="hidden" name="redirect_uri" id="redirect_uri" value="${lodash.escape(redirectUri)}">
|
||||
<button type="submit">Authorize</button>
|
||||
</form>
|
||||
<br>
|
||||
<a href="${lodash.escape(connectUri)}">Nostr Connect</a>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import { Conf } from '@/config.ts';
|
||||
import { getInstanceMetadata } from '@/utils/instance.ts';
|
||||
|
||||
/** Get NIP-46 `nostrconnect://` URI for the Ditto server. */
|
||||
export async function getClientConnectUri(signal?: AbortSignal): Promise<string> {
|
||||
const uri = new URL('nostrconnect://');
|
||||
const { name, description } = await getInstanceMetadata(signal);
|
||||
|
||||
const metadata = {
|
||||
name,
|
||||
description,
|
||||
url: Conf.localDomain,
|
||||
};
|
||||
|
||||
uri.host = Conf.pubkey;
|
||||
uri.searchParams.set('relay', Conf.relay);
|
||||
uri.searchParams.set('metadata', JSON.stringify(metadata));
|
||||
|
||||
return uri.toString();
|
||||
}
|
Loading…
Reference in New Issue