mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-29 08:21:20 +00:00
document what I did for oauth-like flow
This commit is contained in:
parent
0c2e95f0c4
commit
207a0c61fe
@ -24,6 +24,9 @@
|
||||
// pass
|
||||
}
|
||||
} else if (input.match(/@/)) {
|
||||
/**
|
||||
* Check if this is looks like a nip05 profile.
|
||||
*/
|
||||
const profile = await nip05.queryProfile(input);
|
||||
if (profile) {
|
||||
r.pubkey = profile.pubkey;
|
||||
|
@ -12,13 +12,26 @@ export const prepareNdk = ({pubkey, bunkerKey, bunkerToken, bunkerRelay}) => {
|
||||
})
|
||||
|
||||
const nip46Signer = new NDKNip46Signer(instance, pubkey, localSigner)
|
||||
/**
|
||||
* When a signer can authorize an event via a URL, an authUrl event is emitted.
|
||||
*/
|
||||
nip46Signer.on("authUrl", (url) => {
|
||||
const popup = window.open(url, "bunker-auth", "width=600,height=600");
|
||||
|
||||
if (!popup) {
|
||||
// parse the url and add a callbackUrl with the current domain and /bunker-callback
|
||||
/**
|
||||
* If the popup is blocked, we redirect the user to the auth URL and add a callback URL
|
||||
* that will be called with the pubkey generated by the bunker, where we will complete the
|
||||
* nip46 authorization (i.e. send a `connect` command)
|
||||
*/
|
||||
const urlObj = new URL(url)
|
||||
urlObj.searchParams.set("callbackUrl", `${window.location.origin}/bunker-callback`)
|
||||
|
||||
// Just to ensure we redirect to the root of the app but this could be a "connection successful!" page or something like that
|
||||
const selfUrl = new URL(window.location.href)
|
||||
selfUrl.pathname = "/"
|
||||
urlObj.searchParams.set("callbackUrl", selfUrl.toString());
|
||||
|
||||
// Redirect to the auth URL
|
||||
window.location.href = urlObj.toString()
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user