You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已配置Branch.io深度链接,如何实现带动态Token的Magic Link?

Hey there! Great question—Branch.io absolutely supports dynamic deep links with unique tokens embedded in the URL path, you just need to leverage their routing and link generation features correctly. Let me walk you through exactly how to set this up for your magic link use case:

1. Configure Custom Domain & Dynamic Routing Rules

First, make sure you’ve already set up your custom domain (like example.com) in your Branch dashboard. Then head over to Link Settings > Deep Linking > Routing Rules to create a rule that handles your dynamic token path:

  • Create a new routing rule with the path pattern /magiclink/token/:token — the :token here is a dynamic placeholder that Branch will automatically capture from the URL.
  • Set the rule’s destination: this could be a specific screen in your mobile app, or a web endpoint that processes the token. You can also map the captured token value to a custom parameter that gets passed to your app/backend.

Since you need a unique token per link, generating these server-side is the most secure approach (perfect for magic link authentication flows). Here’s how to do it using Branch’s API:

Example Server-Side Generation (Node.js SDK)

const branch = require('branch-sdk');
branch.init('YOUR_BRANCH_LIVE_KEY');

async function createMagicLink(uniqueUserToken) {
  const linkConfig = {
    path: `/magiclink/token/${uniqueUserToken}`, // Insert your unique token here
    channel: 'magic-link',
    feature: 'user-login',
    // Add any other custom parameters you need (e.g., user ID)
    data: {
      user_id: '12345'
    }
  };

  const linkResponse = await branch.link.create(linkConfig);
  return linkResponse.url; // Returns your full dynamic link: https://example.com/magiclink/token/abc123xyz
}

If you need to generate links client-side (for less sensitive use cases), you can use Branch’s mobile/web SDKs to construct the path with your dynamic token similarly.

3. Capture the Token in Your App/Backend

When a user clicks the dynamic link, Branch will parse the token from the URL path and make it available to your application or backend:

  • Mobile Apps: Use the Branch SDK’s session initialization callback to access the token. For example, in Android:
    Branch.getInstance().initSession(object : Branch.BranchReferralInitListener {
      override fun onInitFinished(referralParams: JSONObject?, error: BranchError?) {
        referralParams?.let {
          val token = it.getString("token")
          // Use the token to authenticate the user
        }
      }
    }, intent.data, this)
    
  • Web: You can either extract the token directly from the URL path (e.g., using window.location.pathname.split('/').pop()) or use Branch’s web SDK to retrieve it from the parsed link parameters.

Generate a test link with a sample token (like https://example.com/magiclink/token/test123), click it, and verify:

  • The link routes to the correct destination.
  • The token is correctly captured and passed to your application/backend.
  • You can track link clicks in the Branch dashboard’s Link Analytics section to confirm everything is working.

Branch isn’t limited to static links—their routing system is designed to handle dynamic path parameters exactly like your use case requires. This setup will let you generate unique magic links seamlessly.

内容的提问来源于stack exchange,提问作者Muhammad Owais

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:04:13