-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PKG -- [fcl] Respect service method for discovery (#1375)
* PKG -- [fcl] Respect service method for discovery Addresses: #1374 * PKG -- [fcl] Add changeset Co-authored-by: Chase Fleming <1666730+chasefleming@users.noreply.github.com>
- Loading branch information
1 parent
6b4bc9f
commit dd8cf64
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@onflow/fcl": patch | ||
--- | ||
|
||
Fix issue where authenticating a Discovery API service would not respect service method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {config} from "@onflow/config" | ||
import {invariant} from "@onflow/util-invariant" | ||
import {serviceRegistry} from "../current-user/exec-service/plugins" | ||
|
||
export const makeDiscoveryServices = async () => { | ||
const extensionServices = window?.fcl_extensions || [] | ||
return [...extensionServices, ...serviceRegistry.getServices()] | ||
} | ||
|
||
export async function getDiscoveryService(service) { | ||
const discoveryAuthnInclude = await config.get("discovery.authn.include", []) | ||
const discoveryWalletMethod = await config.first([ | ||
"discovery.wallet.method", | ||
"discovery.wallet.method.default", | ||
]) | ||
const method = service?.method | ||
? service.method | ||
: discoveryWalletMethod | ||
const endpoint = | ||
service?.endpoint ?? | ||
(await config.first(["discovery.wallet", "challenge.handshake"])) | ||
|
||
invariant( | ||
endpoint, | ||
` | ||
If no service is passed to "authenticate," then "discovery.wallet" must be defined in fcl config. | ||
See: "https://docs.onflow.org/fcl/reference/api/#setting-configuration-values" | ||
` | ||
) | ||
|
||
return { | ||
...service, | ||
type: "authn", | ||
endpoint, | ||
method, | ||
discoveryAuthnInclude, | ||
} | ||
} |