Skip to content

Commit

Permalink
PKG -- [fcl] Respect service method for discovery (#1375)
Browse files Browse the repository at this point in the history
* 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
2 people authored and justinbarry committed Sep 6, 2022
1 parent 6b4bc9f commit dd8cf64
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-bears-remain.md
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.
38 changes: 38 additions & 0 deletions packages/fcl/src/discovery/utils.js
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,
}
}

0 comments on commit dd8cf64

Please sign in to comment.