2.1.3 • Published 6 years ago

@vehikl/igloo-server-proxy v2.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Local oauth proxy server

This server should emulate igloo's proxy server for testing purposes

Note

If you are working on an older widget, you might need to specifically use the legacy branch, which is not public.

Integrating with an existing development server

Wrap your application bundler in an express app so all urls are relative/local. Use this for igloo widget repos when possible.

npm install --save @vehikl/igloo-server-proxy
# OR
yarn add @vehikl/igloo-server-proxy
import configureIglooServerProxy from "igloo-server-proxy"
import * as express from "express"
const HTTP_PORT = 3000

const app = express.app()

const proxyOptions = {
  useLegacy: true,
  servicesPath: 'path/to/services'
};

configureIglooServerProxy(app, HTTP_PORT, proxyOptions)
// app - express server
// HTTP_PORT - the port express is serving on
// proxyOptions.useLegacy - load up <host>/<service name>/* oauth endpoints
// proxyOptions.servicesPath - load service config json files from this absolute path

server.listen(HTTP_PORT)

Adding new services

Services should contain the following json:

{
  "clientID": "some-client-id-from-service",
  "clientSecret": "some-client-secret-from-service",
  "site": "http://the-site-where-oauth-happens",
  "authorizationPath": "full/path/to/oauth/authorize",
  "tokenPath": "full/path/to/oauth/token",
  "scope": "Any.scopes Defined.by The.service OrA.EmptyString",
  "resource": "optional/resource",
  "callbackPath": "optional/callback/path",
  "applicationIds": ["ig-name-of-thing"]
}

Both resource and callbackPath are optional, and can be omitted.

authorizationPath and tokenPath can be full URLs if they are not prefixed by the same site. If the path starts with http:// or https://, it will be considered a full URL, otherwise, site will be prefixed to create a full URL.

It is important that the applicationIds match what the widget is submitting so it knows what service to map things to.

To easily add a service, you can use:

npx @vehikl/igloo-server-proxy new

Otherwise service json files are created in constants.js#DEFAULT_SERVICES_PATH.

Test refresh flow

Tokens get persisted, and by default, should be stored in ~/.igloo-proxy-tokens.json. To test refresh flow, log into a service, so the token is properly stored. Then open ~/.igloo-proxy-tokens.json, find the appropriate service, then set ig-yourservice.access_token to either an empty string, or update it with new characters (making the access token invalid). Now refresh the web app, and you should see an initial 401 call through the proxy, followed by the refresh flow.

URL Mapping

OAuth 2.0

All new OAuth endpoints are prefixed with /.api2/api/v1/communities/{communityKey}/oauth2. If the server has useLegacy set to true, there will also be endpoints for /{service-name}, but these should not be relied on. Note that the legacy endpoints are not 1:1 for the newer igloo emulation, only use those if necessary with older widgets.

GET {prefix}/authorize

This endpoint will redirect to the oauth sign-in page, and is often in a pop-up window.

Parameters:

NameRequired?DescriptionValue
applicationIdYesValue mapping to your service.json fileig-{servicename}
authorizeUriYesFull service authorize URLhttps://some-service.com/oauth2/authorize
tokenUriYesFull service get token URLhttps://some-service.com/oauth2/token
scopeYesOAuth scope specification. See your oauth provider's documentation for real values.May contain values like email profile
tokenSubKeyNoSome services require a token sub key, in instances where igloo has two matching applicationIds.Unknown

Response:

HTTP Status CodeDescriptionBody
200 OKSuccessNone
4xxAuthentication ErrorNone
Anything elseServer ErrorNone/Server Message?
GET {prefix}/token
DELETE {prefix}/token

This endpoint retrieves manages the current oauth tokens The GET variant retrieves it, the DELETE variant will remove it.

Parameters:

NameRequired?DescriptionValue
applicationIdYesValue mapping to your service.json fileig-{servicename}

Response:

HTTP Status CodeDescriptionBody
200 OKSuccess(Using GET) { access_token: A, refresh_token: B, expiresAt: C }
4xxAuthentication ErrorNone
Anything elseServer ErrorNone/Server Message?
POST {prefix}/refreshtoken

This endpoint retrieves the current access and refresh tokens associated with the service. This will refresh the tokens in the igloo server, but will require a secondary call to GET {prefix}/token to get the updated tokens.

JSON Body:

NameRequired?DescriptionValue
ApplicationIdYesValue mapping to your service.json fileig-{servicename}
RefreshTokenYesThe refresh token, from GET {prefix}/tokenAn OAuth token
RefreshTokenURIYesFull service refresh token URLhttps://some-service.com/oauth2/refresh

Headers:

NameRequired?DescriptionValue
Content-TypeYesTell the server the post body formatapplication/json

Response:

HTTP Status CodeDescriptionBody
200 OKSuccessNone
4xxAuthentication ErrorNone
Anything elseServer ErrorNone/Server Message?

Configuring a Service

Server-Side

  • Redirect URL: http://your-server-proxy-address:port/.api2/api/v1/communities/{your-community-key}/oauth2/callback
    • Make take the form of http://localhost:3000/.api2/api/v1/communities/igloo-key==/oauth2/callback
2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago