AngularJS + OAuth

Asa*_*saf 48 oauth angularjs

我正在尝试为我的Angular App编写登录解决方案,
这意味着允许用户通过Facebok/Google/Twitter或正常注册进行连接.
我发现Angular-OAuth很有用,但它似乎不适用于Facebook(或Twitter).

有人知道这个全包解决方案吗?

Ana*_*kar 52

这是一个使用角度js重定向的简单示例

以下是如何重定向到身份验证

angular.module('angularoauthexampleApp')
  .controller('MainCtrl', function ($scope) {
    $scope.login=function() {
        var client_id="your client id";
        var scope="email";
        var redirect_uri="http://localhost:9000";
        var response_type="token";
        var url="https://accounts.google.com/o/oauth2/auth?scope="+scope+"&client_id="+client_id+"&redirect_uri="+redirect_uri+
        "&response_type="+response_type;
        window.location.replace(url);
    };
  });
Run Code Online (Sandbox Code Playgroud)

以下是验证后如何处理重定向

angular
  .module('angularoauthexampleApp', [
  ])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/access_token=:accessToken', {
        template: '',
        controller: function ($location,$rootScope) {
          var hash = $location.path().substr(1);

          var splitted = hash.split('&');
          var params = {};

          for (var i = 0; i < splitted.length; i++) {
            var param  = splitted[i].split('=');
            var key    = param[0];
            var value  = param[1];
            params[key] = value;
            $rootScope.accesstoken=params;
          }
          $location.path("/about");
        }
      })
  });
Run Code Online (Sandbox Code Playgroud)

更完整的信息http://anandsekar.github.io/oauth2-with-angularjs/

  • 为什么这不是选择的答案? (10认同)

Thi*_*ult 40

看看oauth.io

  • 在Javascript中轻松实现
  • 80多个OAuth提供商
  • 快速安全

  • 这不是免费的. (15认同)
  • OAuth.io有一个大型免费增值模式(每月最多1000个用户)和Github上提供的开源版本:https://github.com/oauth-io/oauthd (5认同)
  • 是免费的吗? (2认同)

Ped*_*cía 13

有一个免费的开源替代免费增值oauth.io:hello.js

  • OAuth.io也是他的OAuth deamon的开源:github.com/oauth-io/oauthd;) (6认同)
  • 所有客户端都可以在github上找到:[js](https://github.com/oauth-io/oauth-js),[ios](https://github.com/oauth-io/oauth-ios),[ android](https://github.com/oauth-io/oauth-android),[phonegap](https://github.com/oauth-io/oauth-phonegap),[flex](https:// github .com/oauth-io/oauth-flex),[php](https://github.com/oauth-io/sdk-php),[node.js](https://github.com/oauth-io/sdk-node)以及更多内容).您可以将它们配置为使用oauthd而不是oauth.io (2认同)

Sun*_* D. 6

看看Github 上的Satellizer项目.我刚刚开始使用它,看起来很有希望.

它使用JSON Web令牌,并允许登录:电子邮件+密码,Facebook,Twitter,谷歌和任何其他OAuth 1.0/2.0提供商.

客户端代码解决方案,您必须自己实现服务器端.对许多服务器端语言的工作流程和代码示例有很好的描述.