npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-cas-auth-api

v0.1.4

Published

Module to authenticate angular webapps with CAS access-token protected APIs.

Downloads

10

Readme

angular-cas-auth-api

Module to authenticate angular webapps with CAS access-token protected APIs.

Originally this module was written to support The Key (Cru CAS) before it had OAuth support. This has since been added and is the recommended way of authenticating.

About

This module when using OAuth takes users through the following process:

  1. app makes a request to a managedApi without a session
  2. module checks URL fragment and cache for access_token (none found)
  3. module redirects user to The Key using the implicit OAuth grant
  4. user logs in and The Key redirects user back to redirect url in module configuration with access_token(The Key) in URL fragment
  5. app makes a request to a managedApi without a session
  6. module checks URL fragment and cache for access_token (found)
  7. module contacts The Key (casTicketPath) using access_token: access_token(The Key) and service: managedApi being requested
  8. Key returns a ticket to module
  9. module uses ticket to authenticate with auth-api(authenticationApiBaseUrl)
  10. auth-api returns access_token(service) to module
  11. original request sent with access_token(service) to service

Installation

Choose your preferred method:

  • Bower: bower install angular-cas-auth-api
  • NPM: npm install --save angular-cas-auth-api
  • Download: angular-cas-auth-api

Usage

1. Request Client ID (optional)

If you are going to use The Key (Cru CAS) as your CAS authenticator you will need to get a Client ID. send an email to [[email protected]](mailto:[email protected]?subject=New OAuth Client Request for The Key) with the subject New OAuth Client Request for The Key.

2. Configure casAuthApi:
angular.module('myApp', ['cas-auth-api'])
  .config(['casAuthApiProvider', function(casAuthApiProvider) {
    casAuthApiProvider.configure({
        requireAccessToken: true,
        cacheAccessToken: true, // If true you must include lscache #optional
        redirectUrl: 'http://localhost/', // URL to redirect to after OAuth Authentication #required
        clientId: '1234567890', // Client ID related to redirect URL #required
        oAuth: true // #required
    });
  }]);
3. Catch casAuthApi errors and do something with them (optional):
angular.module('myApp', ['cas-auth-api'])
  .run(['$rootScope', '$window', function($rootScope, $window) {
    $rootScope.$on('cas-auth-api:error', function(event, rejection) {
      if ('ERR_SERVICE' === rejection.code) {
        // retrieving service object failed
      }

      if ('ERR_TICKET' === rejection.code) {
        // retrieving ticket object failed
      }

      if ('ERR_TOKEN' === rejection.code) {
        // retrieving token object failed
      }

      // Redirect to `/login` with the `error_reason`.
      return $window.location.href = '/login?error_reason=' + rejection.message;
    });
  }]);

NOTE: An event cas-auth-api:error will be sent every time a responseError is emitted:

  • { code: 'ERR_SERVICE', message: 'Failed to fetch service.'}
  • { code: 'ERR_TICKET', message: 'Failed to fetch ticket.'}
  • { code: 'ERR_TOKEN', message: 'Failed to fetch token.'}

API

CasAuthApiProvider

Configuration defaults:

casAuthApiProvider.configure({
  endpoints: {
      'service': 'service',
      'token': 'token/new'
  },
  ticketUrl: '',
  maxAttempts: 3,
  requireAccessToken: false,
  cacheAccessToken: false,
  cacheExpiresMinutes: 25,
  managedApis: [],
  casBaseUrl: 'https://thekey.me/cas/' ,
  casLoginPath: '/login',
  casTicketPath: '/api/oauth/ticket',
  oAuth: false,
  authenticationApiBaseUrl: 'https://auth-api.cru.org/v1'
});

Catch and authenticate urls:

/**
* Add a url to the managed API list
*
* @param {string|Array.<string>} url
* @returns {*}
*/
 casAuthApi.addManagedApi( 'https://ministry-view-api.cru.org/ministry_view/' );

Contributing & Development

Contribute

Found a bug or want to suggest something? Take a look first on the current and closed issues. If it is something new, please submit an issue.

Develop

It will be awesome if you can help us evolve angular-cas-auth-api. Want to help?

  1. Fork it.
  2. npm install.
  3. Do your magic.
  4. Run the tests: gulp test.
  5. Build: gulp build
  6. Create a Pull Request.

Todo

  • Write tests
  • refactor to ES6 with Babel
  • Add support for OAuth attributes endpoint available https://thekey.me/cas/api/oauth/attributes
  • Add support for expires_in parameter in the implicit OAuth response and set cache to expire at that time