【问题标题】:Redirecting user into iOS application when reseting password重置密码时将用户重定向到iOS应用程序
【发布时间】:2019-05-04 14:26:28
【问题描述】:

目前,我正在触发这样的密码重置:

  static func firebasePasswordReset(email:String, responseError:@escaping (ResponseError?)->Void, completion:@escaping (
        String)->Void){

        Auth.auth().sendPasswordReset(withEmail: email) { (error) in
            if(error != nil){
              responseError(ResponseError.custom(error?.localizedDescription ?? "Unknow error occured. Please try again."))
            }else{
                completion(NSLocalizedString("Password reset link sent. Please check \(email).", comment: ""))
            }
        }
    }

尽管一切正常,并且发送了相应电子邮件的链接,但用户会获得我在 Firebase 控制台中为我的网站设置的链接。

所以它是https://myprojectname/reset-password.html 页面。

现在,对于 iOS 用户,我不希望他们去网站重设密码。我想将他们重定向到一个应用程序,并在他们的 iOS 应用程序中打开一个表单。这有可能吗?

【问题讨论】:

标签: ios swift firebase firebase-authentication


【解决方案1】:

1- AppDelegate

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
        if let url = userActivity.webpageURL {
            if url.path.range(of: "/reset-password.html") != nil {
                if let passwordToken = url.getQueryItemValueForKey("token") {
                    let resetPasswordController= ResetPasswordController()
                    resetPasswordController?.passwordToken = passwordToken
                    self.window?.rootViewController = resetPasswordController
                    self.window?.makeKeyAndVisible()
                }
            }
        }

        return true
    }

2 - 将您的域添加到权利中的关联域。

<key>com.apple.developer.associated-domains</key>
<array>
    <string>applinks:www.yourdomain.com</string>
    <string>applinks:yourdomain.com</string>
</array>

3- 创建 apple-app-site-association 文件

创建一个apple-app-site-association 文件,mime 类型为 json,但没有文件扩展名。 YOUR_APP_ID 类似于 XXXXXXX.com.mycompany.projectname

并确保它必须可以通过公共 https://yourdomain.com/apple-app-site-associationcontent-typeapplication/json 访问

{
   "applinks": {
   "apps": [],
   "details": [
      {
         "appID": "YOUR_APP_ID",
         "paths": [
            "/reset-password.html*"
         ]
      }
    ]
}

更新:您还必须使用 https 提供 apple-app-site-association 文件。 https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html

4- 在电子邮件中,链接应包含密码令牌,类似这样,

<a href="http://yourdomain.com/reset-password.html?token=BLABLABLABLABLABLABAL">Reset Your Password</a>

5- 决赛

在您的ResetPasswordController 中创建密码重置表单,

方法一:当用户提交表单时,将token 发送到您的服务器。检查令牌是否存在等。从您的 API 返回 true 或 false。

方法二:通过 API 检查令牌是否存在,然后显示您的重置表单。

【讨论】:

    猜你喜欢
    • 2019-11-06
    • 2017-08-24
    • 2015-05-17
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 2017-09-26
    相关资源
    最近更新 更多