1.2.6 • Published 6 years ago

onestop-auth v1.2.6

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

Onestop Auth Module

AuthModule is a set of essential modules for Onestop Angular application.

What's included:

  • Login and Spaces Select Page Templete
  • Authentication Service
  • Spaces Service to store and retrieve spaces/spaceId/user roles in localstorage
  • Onestop http interceptor to manage http calls, eg. setup common headers and handle errors

Installation

Before install this module, make sure your npm are under onstop npm registry. To check your npm registry, run

npm config get registry

To change your npm registry to Onestop npm, run

npm config set registry http://packages.prod.1-stop.biz/npm/npm/

To install this module, under the project directory run

npm install --save onestop-auth

Getting started

Import the AuthModule in your root application module:

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

import {AppComponent} from './app.component';
import {AuthInterceptor, AuthModule} from 'onestop-auth';
import {AppRoutingModule} from './app-routing.module';
import {HomeComponent} from './home.component';
import {HTTP_INTERCEPTORS} from '@angular/common/http';

@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        AppRoutingModule,
        // authenticationUrl and appPrefix are required
        AuthModule.forRoot({
            authenticationUrl: "https://api-40.1-stop.biz/CPMSGW/api/v1/user/login",
            authorisationBaseUrl: "https://api-40.1-stop.biz/CPMSGW/api/v1",
            appPrefix: "CPMS_"
        })
    ],
    declarations: [AppComponent, HomeComponent],
    providers: [{
        provide: HTTP_INTERCEPTORS,
        useClass: AuthInterceptor,
        multi: true,
    }],
    bootstrap: [AppComponent]
})
export class AppModule {
}

More configuration details see Configuration Options

Setting routes:

import {RouterModule, Routes} from '@angular/router';
import {NgModule} from '@angular/core';
import {HomeComponent} from './home.component';
import {LoginComponent, SpacesComponent} from 'onestop-auth';

const routes: Routes = [
    {
        path: '',
        component: HomeComponent
    },
    {
        path: 'login',
        component: LoginComponent,
    },
    {
        path: 'spaces',
        component: SpacesComponent,
    },
    { path: '', redirectTo: 'login', pathMatch: 'full'},
    { path: '**', redirectTo: ''},
];

@NgModule({
    imports: [RouterModule.forRoot(routes)],
    exports: [RouterModule]
})
export class AppRoutingModule {
}

Configuration

NameDefaultDescription
*authenticationUrlnullThe Authentication URL to post user name and password, eg. https://api-40.1-stop.biz/CPMSGW/api/v1/user/login
*appPrefixnullOnestop App prefix, eg. CPMS_
authorisationBaseUrlnullThe base url in relation to user space url and user roles url
redirectTo/The Url that will be redirected to when successfully login
clientId'1STOP'ClientId in Authentication payload
spaceIdnullProvide a default Space ID
defaultSpaceIdtrueIf default space ID is not provided, and you don't want to go to space selection page to select a ID, you can set this config to true, then the app will skip spaces page and set up first space in user's available spaces.
spaceUrlspacesSpace selection page URL
userSpacesUrl/user/spaceIdsURL to get user spaces, will combine with authorisationBaseUrl
userRolesUrl/user/facilitiesURL to get user roles, will combine with authorisationBaseUrl
1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago