【问题标题】:Azure AD B2C Refresh Token/ID Token iOS Swift 4Azure AD B2C 刷新令牌/ID 令牌 iOS Swift 4
【发布时间】:2018-08-04 05:51:22
【问题描述】:

我正在开发一个 iOS 应用程序,利用带有 AADB2C 的 ROPC 流程作为支持此功能的后端端点。 https://login.microsoftonline.com/{TENANTNAME}.onmicrosoft.com/oauth2/v2.0/token?p={ROPC Policy Name}

在客户第一次使用电子邮件/密码成功登录时,我已经成功地请求和检索了 access tokenrefresh tokenID token

在此成功登录后,每次后续登录,我们都希望利用生物识别技术(触摸/面部 ID)。我的第一个想法是将 refreshToken 存储在钥匙串中,在强制用户输入他/她的电子邮件/密码之前检查 refreshToken 的存在。

如果存在refreshToken,那么我想我会调用令牌端点,使用?p=refresh_token,而不是?p={INSERT ROPC Policy Name},如果我返回成功,那么我使用Touch/Face ID登录。

我的另一个想法是只使用令牌 ID 进行身份验证。

因此我的问题有两个:

  1. 更好的做法是什么 - 让 iOS 原生应用程序使用刷新令牌或 ID 令牌。

  2. 我尝试使用刷新令牌,将{ROPC Policy Name} 参数换成?p=refresh_token,但每次我尝试配置请求时,都会收到错误消息"The request body must contain the following parameter: 'grant_type'" 我添加了“refresh_token”作为键 grant_type 的值,但仍然出现该错误。 -- 为什么会这样,如果刷新令牌 grant_type 更好,我该如何解决。

【问题讨论】:

    标签: ios swift azure azure-ad-b2c


    【解决方案1】:

    你是对的。

    您可以将刷新令牌保存到密钥链中,并保护此刷新令牌与 Face ID 或 Touch ID 的使用。

    the "Configure the resource owner password credentials flow in Azure AD B2C" documentThe "Redeem a refresh token" section 描述了如何兑换为资源所有者策略颁发的刷新令牌:

    POST /{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/token HTTP/1.1
    Host: login.microsoftonline.com
    Content-Type: application/x-www-form-urlencoded
    
    grant_type=refresh_token
    &response_type=id_token
    &client_id={client_id}
    &resource={client_id}
    &refresh_token={refresh_token}
    

    【讨论】:

      【解决方案2】:

      感谢@Chris Padgett。我能够使用稍微修改的请求启动并运行 AppAuth。这是我的代码。

      let authorizationEndpoint = URL(string: "https://login.microsoftonline.com/{TENANT_NAME}.onmicrosoft.com/oauth2/v2.0/authorize?p={ROPC_POLICY_NAME}")
      let tokenEndpoint = URL(string: "https://login.microsoftonline.com/{TENANT_NAME}.onmicrosoft.com/oauth2/v2.0/token?p={ROPC_POLICY_NAME}")
      let configuration = OIDServiceConfiguration(authorizationEndpoint: authorizationEndpoint!, tokenEndpoint: tokenEndpoint!)
      
      //Configuring the token request
      let tokenExchangeRequest = OIDTokenRequest(
          configuration: configuration,
          grantType: OIDGrantTypeRefreshToken,
          authorizationCode: nil,
          redirectURL: self.redirectUri!,
          clientID: self.clientId,
          clientSecret: nil,
          scope: "openid \(self.clientId) offline_access",
          refreshToken: {INSERT_REFRESH_TOKEN_HERE},
          codeVerifier: nil,
          additionalParameters: nil
      )
      
      //Performing token request
      OIDAuthorizationService.perform(tokenExchangeRequest, callback: { tokenResponse, error in
      
          if tokenResponse == nil {
              print("Token request error: %@", error?.localizedDescription as Any)
          } else {
              guard let tokenResponse = tokenResponse else { return }
              ...handle tokenResponse how you need to...
          }
      })
      

      【讨论】:

        猜你喜欢
        • 2018-01-08
        • 2018-01-21
        • 2020-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-22
        • 1970-01-01
        相关资源
        最近更新 更多