AngularJS 的 OAuth2 模块 angular-oauth2

怼烎@ 2022-05-20 08:19 352阅读 0赞

angular-oauth2 详细介绍

angular-oauth2 是 AngularJS 的 OAuth2 认证模块,使用 ES6 编写。

使用方法:

  1. 引入 js 库:

  2. 配置 OAuth 和 OAuthToken

    angular.module(‘myApp’, [‘angular-oauth2’])
    .config([‘OAuthProvider’, function(OAuthProvider) {

    1. OAuthProvider.configure({
    2. baseUrl: 'https://api.website.com',
    3. clientId: 'CLIENT_ID',
    4. clientSecret: 'CLIENT_SECRET',
    5. });

    }]);

  3. 错误处理:

    angular.module(‘myApp’, [‘angular-oauth2’])
    .run([‘$rootScope’, ‘$window’, function($rootScope, $window) {

    1. $rootScope.$on('oauth:error', function(event, rejection) {
    2. // Ignore `invalid_grant` error - should be catched on `LoginController`.
    3. if ('invalid_grant' === rejection.data.error) {
    4. return;
    5. }
    6. // Redirect to `/login` with the `error_reason`.
    7. return $window.location.href = '/login?error_reason=' + rejection.data.error;
    8. });

    }]);

发表评论

表情:
评论列表 (有 0 条评论,352人围观)

还没有评论,来说两句吧...

相关阅读

    相关 OAuth2

    1.什么是OAuth2 OAUTH协议为用户资源的授权提供了一个安全的、开放而又简易的标准。同时,任何第三方都可以使用OAUTH认证服务,任何服务提供商都可以实现自身的O