appirio-tech / accounts-app

accounts.topcoder.com
2 stars 25 forks source link

Goal

Standardize auth logic across all Topcoder frontend apps.

This repo contains several pieces:

  1. The accounts app itself, as deployed at accounts.topcoder.com
  2. The connector mini-app, as deployed at accounts.topcoder.com/connector.html
  3. An npm module exposing:
    • The connector-wrapper module that provides
    • A library of shared auth functionality (token handling, etc)

Using Connector in your app

Install

> npm install --save tc-accounts

Configure

The connector exports a configureConnector method that must be invoked before any of the other methods, which likely means the entry of your app, or the entry of your auth logic. This will create and attach the connector iFrame to the DOM in your app.

import { configureConnector } from 'tc-accounts'

configureConnector({
  connectorUrl: 'https://accounts.topcoder.com/connector.html',
  frameId: 'tc-accounts-iframe'
})

Use

import { getFreshToken } from 'tc-accounts'

getFreshToken().then( token => {
  console.log(token)
})

API Reference

const config = function($httpProvider, jwtInterceptorProvider) {
  function jwtInterceptor() {
    return getFreshToken()
  }

  jwtInterceptorProvider.tokenGetter = jwtInterceptor

  $httpProvider.interceptors.push('jwtInterceptor')
}

Contributing

Getting Started

If you only need to work on the app itself, getting up and running is super simple.

> npm install
> npm run dev

Testing integration locally

If you need to test your integration locally, you'll need a few more steps. The iframe technique we are using here does not play well with webpack-dev-server, and we need to serve two apps from the same subdomain (port, in this case).

> npm install
> npm run build:dev
> npm run build:connector

You'll need to rerun the build:dev and build:connector commands manually to see your updates.

© 2017 Topcoder. All Rights Reserved