Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support deeplink #212

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions go/wallet/discovery_handler.go

Large diffs are not rendered by default.

32 changes: 31 additions & 1 deletion go/wallet/service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ type ServicePostResponse struct {
Local Service `json:"local"`
}

type FCLClient struct {
Platform string `json:"platform"`
}

type FCLConfig struct {
Client FCLClient `json:"client"`
}

type FCLMessage struct {
Config FCLConfig `json:"config"`
}

func getMethod(fclMessageJson []byte) string {

var fclMessage FCLMessage
err := json.Unmarshal(fclMessageJson, &fclMessage)

if err != nil {
fmt.Println("Error:", err)
return "VIEW/IFRAME"
}

if fclMessage.Config.Client.Platform == "react-native" {
return "VIEW/MOBILE_BROWSER"
}

return "VIEW/IFRAME"
}

func (server *server) postServiceHandler(w http.ResponseWriter, r *http.Request) {
service := strings.TrimPrefix(r.URL.Path, "/api/")
Expand All @@ -38,6 +66,8 @@ func (server *server) postServiceHandler(w http.ResponseWriter, r *http.Request)
}

fclMessageJson, err := ioutil.ReadAll(r.Body)
method := getMethod(fclMessageJson)

if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
Expand Down Expand Up @@ -88,7 +118,7 @@ func (server *server) postServiceHandler(w http.ResponseWriter, r *http.Request)
FVsn: "1.0.0",
Type: "local-view",
Endpoint: baseUrl + "/fcl/" + service,
Method: "VIEW/IFRAME",
Method: method,
Params: map[string]string{
"pollingId": fmt.Sprint(pollingId),
"channel": "back",
Expand Down
3 changes: 3 additions & 0 deletions hooks/useConnectedAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export type ConnectedAppConfig = {
icon: string
title: string
}
client?: {
platform?: string
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion hooks/useFclData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useFclData<T>({

useEffect(() => {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has("channel") && urlParams.get("channel") === "back") {
if (urlParams.has("fclMessageJson")) {
const fclMessageJson = urlParams.get("fclMessageJson")
if (!fclMessageJson) {
throw new Error("fclMessageJson is missing")
Expand Down
2 changes: 2 additions & 0 deletions src/accountAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export async function chooseAccount(
) {
const {address, keyId} = account
const {nonce, appIdentifier} = connectedAppConfig.body
const {client} = connectedAppConfig.config

let compSig
if (nonce) {
Expand All @@ -98,6 +99,7 @@ export async function chooseAccount(
compSig,
keyId,
includeRefresh: false,
client,
})

localStorage.setItem("connectedAppConfig", JSON.stringify(connectedAppConfig))
Expand Down
19 changes: 15 additions & 4 deletions src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ function entries<T>(arr: Array<T> = []) {
return Object.fromEntries(arrEntries)
}

const getMethod = (backchannel: boolean, platform: string | null) => {
return backchannel
? "HTTP/POST"
: platform === "react-native"
? "DEEPLINK/RPC"
: "IFRAME/RPC"
}

const entry = (
scopes: Set<string>,
key: string,
Expand All @@ -64,6 +72,7 @@ export const buildServices = ({
compSig,
keyId,
includeRefresh = false,
client,
}: {
baseUrl: string
address: string
Expand All @@ -72,8 +81,10 @@ export const buildServices = ({
compSig: string | undefined
keyId?: number
includeRefresh?: boolean
client?: {platform?: string}
}) => {
const backchannel = isBackchannel()
const platform = client?.platform || null

const services: AuthResponseService[] = [
{
Expand All @@ -82,7 +93,7 @@ export const buildServices = ({
type: "authn",
uid: "fcl-dev-wallet#authn",
endpoint: backchannel ? `${baseUrl}/api/authn` : `${baseUrl}/fcl/authn`,
method: backchannel ? "HTTP/POST" : "IFRAME/RPC",
method: getMethod(backchannel, platform),
id: address,
identity: {
address: address,
Expand All @@ -100,7 +111,7 @@ export const buildServices = ({
type: "authz",
uid: "fcl-dev-wallet#authz",
endpoint: backchannel ? `${baseUrl}/api/authz` : `${baseUrl}/fcl/authz`,
method: backchannel ? "HTTP/POST" : "IFRAME/RPC",
method: getMethod(backchannel, platform),
identity: {
address: address,
keyId: Number(keyId),
Expand All @@ -114,7 +125,7 @@ export const buildServices = ({
endpoint: backchannel
? `${baseUrl}/api/user-sig`
: `${baseUrl}/fcl/user-sig`,
method: backchannel ? "HTTP/POST" : "IFRAME/RPC",
method: getMethod(backchannel, platform),
id: address,
data: {addr: address, keyId: Number(keyId)},
params: {},
Expand Down Expand Up @@ -149,7 +160,7 @@ export const buildServices = ({
endpoint: backchannel
? `${baseUrl}/api/authn-refresh`
: `${baseUrl}/fcl/authn-refresh`,
method: backchannel ? "HTTP/POST" : "IFRAME/RPC",
method: getMethod(backchannel, platform),
id: address,
data: {
f_type: "authn-refresh",
Expand Down