在 Google Cloud Endpoints 中登录 Facebook [英] Facebook login in Google Cloud Endpoints

查看:27
本文介绍了在 Google Cloud Endpoints 中登录 Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释一下使用其他 OAuth2 提供商实现登录过程的步骤吗此链接 Google Cloud Endpoints with another oAuth2 provider 几乎没有提供有关编写的信息自定义身份验证,但我想对于像我这样的初学者来说还不够,请给出详细的步骤.尤其是对 Facebook 感兴趣.

Can someone explain steps to implement login process with other OAuth2 providers This link Google Cloud Endpoints with another oAuth2 provider gives little info about writing custom authentication, but I guess for beginner like me that's not enough, please give detailed steps. Especially, interested in Facebook.

推荐答案

您需要根据 Facebook 的文档和您将客户端应用程序部署到的环境(浏览器、iOS 和 Android)来实施 Facebook 的客户端 API.这包括向他们注册您的应用程序.您注册的应用程序将引导用户完成身份验证流程,最后您的客户端应用程序将有权访问短期访问令牌.Facebook 有多种类型的访问令牌,但听起来您感兴趣的一种称为用户访问令牌,因为它标识了授权用户.

You need to implement Facebook's client side APIs according to their documentation and the environment you are deploying your client app to (Browser vs iOS vs Android). This includes registering your app with them. Your registered app will direct the user to go through an authentication flow and at the end of it your client app will have access to a short-lived access token. Facebook has multiple types of access tokens, but the one it sounds like you're interested in is called a User Access Token since it identifies an authorized user.

通过字段或标头将访问令牌传递到您的 Cloud Endpoints API.在您的 API 代码内部接收访问令牌并实施 Facebook 的 API,以检查访问令牌的有效性.this SO question的第一个答案使它看起来相当简单,但您可能想再次参考他们的文档.如果该检查通过,那么您将运行 API 代码,否则抛出异常.

Pass the access token to your Cloud Endpoints API via a field or header. Inside of your API code receive the access token and implement Facebook's API that checks the validity of the access token. The first answer on this SO question makes it look rather easy, but you probably want to reference their documentation again. If that check passes then you would run your API code, otherwise throw an exception.

您通常还需要实施缓存机制,以防止为每个 Cloud Endpoints 请求调用 Facebook 服务器端验证 API.

You will typically also want to implement a caching mechanism to prevent calling the Facebook server side validation API for each Cloud Endpoints request.

最后,我提到您的客户端应用程序有一个短暂的令牌.如果您有一个基于浏览器的客户端应用程序,那么您可能希望将其升级为长期存在的令牌.Facebook 也有一个流程,它涉及您的 API 代码请求一个长期存在的令牌和短期令牌.然后,您需要将该长期存在的令牌传输回客户端应用,以用于未来的 Cloud Endpoints API 调用.

Finally, I mentioned that your client app has a short lived token. If you have a client app that is browser-based then you will probably want to upgrade that to a long lived token. Facebook has a flow for that as well which involves your API code requesting a long lived token with the short lived one. You would then need to transfer that long lived token back to the client app to use for future Cloud Endpoints API calls.

如果您的客户端应用基于 iOS 或 Android,那么您的令牌由 Facebook 代码管理,您只需在需要时从相应的 API 请求访问令牌.

If your client app is iOS or Android based then your tokens are managed by Facebook code and you simply request access tokens from the respective APIs when you need them.

这篇关于在 Google Cloud Endpoints 中登录 Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆