使用oauth2服务(如facebook)授权我的应用程序访问第三方应用程序



我使用facebookconnect来授权我网站上的用户,但我也为用户弹出了第三方服务。这项第三方服务也在使用脸书连接来授权其用户。

我不希望每个用户都被迫经历两次授权阶段。有没有一种方法可以让用户在登录我的服务时授权第三方服务,获得一些令牌,并在我弹出第三方服务器时使用它?

您可以使用Facebook SDK的getLoginStatus方法来确定用户是否已经授权您的应用程序,并且当前正在登录。如果用户使用FB登录您的网站,他将不必再次登录。

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // the user is logged in and has authenticated your
    // app, and response.authResponse supplies
    // the user's ID, a valid access token, a signed
    // request, and the time the access token 
    // and signed request each expire
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
  } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
  } else {
    // the user isn't logged in to Facebook.
  }
 });

因此,用户只需登录一次,并且只需第一次对应用程序进行授权。你可以在这里阅读更多关于这种方法的信息。

相关内容

最新更新