简体   繁体   English

Android和Twitter Fabric:发送特定的电话号码以使用Twitter-fabric Digits API进行验证

[英]Android & Twitter Fabric: Send a Particular Phone Number for Verification in Twitter-fabric Digits API

I have already added code for Verification of Phone Number in my application, once a user has verified his phone number I add that number to my database. 我已经在我的应用程序中添加了用于验证电话号码的代码,一旦用户验证了他的电话号码,便将该号码添加到我的数据库中。

Now if User Logins again I ask the user to verify his phone number again, but twitter fabric allows him/her to verify any number but I want twitter fabric Digits to verify the phone number which I provide to twitter fabrics Digits from my database. 现在,如果用户再次登录,我要求用户再次验证他的电话号码,但是twitter fabric允许他/她验证任何号码,但我希望twitter fabric Digits可以验证我从数据库中提供给twitter fabrics Digits的电话号码。

Todd from the Fabric team here. 来自Fabric团队的Todd。

The most important consideration here is that you obtain the Digits details from your server and then send directly to us. 这里最重要的考虑因素是您从服务器获取位数详细信息,然后直接发送给我们。 That way your server receives the trusted user information. 这样,您的服务器就会收到受信任的用户信息。

First, query Digits to request the userID, phone number and OAuth tokens. 首先,查询Digits以请求用户ID,电话号码和OAuth令牌。 You should use OAuth Echo to achieve this. 您应该使用OAuth Echo来实现。

To generate OAuth Echo headers. 生成OAuth Echo标头。

The DigitsOAuthSigning class provides a convenient way to generate authorization headers for a user session. DigitsOAuthSigning类提供了一种方便的方法来为用户会话生成授权标头。 DigitsOAuthSigning relies on the TwitterAuthConfig as well as a TwitterAuthToken . DigitsOAuthSigning依赖于TwitterAuthConfigTwitterAuthToken

The TwitterAuthConfig class encapsulates the credentials to identify your Twitter or Digits application. TwitterAuthConfig类封装凭据以标识您的Twitter或Digits应用程序。 You can get this object from the Digits class. 您可以从Digits类获取此对象。

The TwitterAuthToken class represents the user credentials of a Twitter of Digits user. TwitterAuthToken类表示Digits用户的Twitter用户凭证。 You can get this object from a TwitterSession or DigitsSession . 您可以从TwitterSessionDigitsSession获取此对象。

TwitterAuthConfig authConfig = TwitterCore.getInstance().getAuthConfig();
TwitterAuthToken authToken = session.getAuthToken();
DigitsOAuthSigning oauthSigning = new DigitsOAuthSigning(authConfig, authToken);

The easiest way to use OAuth Echo is by generating the authorization headers in the client. 使用OAuth Echo的最简单方法是在客户端中生成授权标头。 Use these headers to make an OAuth Echo request from outside the app (eg from your web server server). 使用这些标头可以从应用程序外部(例如,从Web服务器服务器)发出OAuth Echo请求。

Map<String, String> authHeaders = oauthSigning.getOAuthEchoHeadersForVerifyCredentials();

The authHeaders map contains the X-Auth-Service-Provider and X-Verify-Credentials-Authorization keys. authHeaders映射包含X-Auth-Service-ProviderX-Verify-Credentials-Authorization密钥。 Your web server should take the value in X-Verify-Credentials-Authorization , and use it to set the Authorization header for a request to the URL in X-Auth-Service-Provider . 您的Web服务器应采用X-Verify-Credentials-Authorization ,并使用它为X-Auth-Service-Provider的URL设置请求的Authorization标头。 Once you have the headers, you can send those to your web server to verify the credentials. 获得标头后,可以将其发送到Web服务器以验证凭据。

URL url = new URL("http://api.yourbackend.com/verify_credentials.json");
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setRequestMethod("GET");

// Add OAuth Echo headers to request
for (Map.Entry<String, String> entry : authHeaders.entrySet()) {
  connection.setRequestProperty(entry.getKey(), entry.getValue());
}

// Perform request
connection.openConnection();

For additional security, on your web host you should: 为了提高安全性,在您的虚拟主机上,您应该:

Validate that the oauth_consumer_key header value in the X-Verify-Credentials-Authorization matches your oauth consumer key, to ensure the user is logging into your site. 验证X-Verify-Credentials-Authorization中的oauth_consumer_key标头值X-Verify-Credentials-Authorization与您的oauth使用者密钥相匹配,以确保用户登录到您的站点。 You can use an oauth library to parse the header and explicitly match the key value, eg parse(params['X-Verify-Credentials-Authorization']).oauth_consumer_key=<your oauth consumer key>. 您可以使用oauth库来解析标头并明确匹配键值,例如parse(params['X-Verify-Credentials-Authorization']).oauth_consumer_key=<your oauth consumer key>.

Verify the X-Auth-Service-Provider header, by parsing the uri and asserting the domain is api.digits.com, to ensure you are calling Digits. 通过解析uri并断言域为api.digits.com来验证X-Auth-Service-Provider标头,以确保您正在调用Digits。

Validate the response from the verify_credentials call to ensure the user is successfully logged in 验证来自verify_credentials调用的响应,以确保用户成功登录

Consider adding additional parameters to the signature to tie your app's own session to the Digits session. 考虑将其他参数添加到签名,以将您自己的应用程序会话与Digits会话绑定在一起。 Use the alternate form getOAuthEchoHeadersForVerifyCredentials(Map<String, String> optParams) to provide additional parameters to include in the OAuth service URL. 使用替代形式getOAuthEchoHeadersForVerifyCredentials(Map<String, String> optParams)提供其他参数以包括在OAuth服务URL中。 Verify these parameters are present in the service URL and that the API request succeeds. 验证服务URL中是否存在这些参数以及API请求是否成功。

Reference on Verifying Digits Users in Android 关于在Android中验证数字用户的参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM