1.0.2 • Published 2 years ago

@kimaya-hybrid/ngx-auth-service v1.0.2

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

AuthHandler

This project was generated with Angular CLI version 8.1.0.

How Install

npm install @kimaya/ngx-auth-service

Dependency

You need to install dependencies manually

CookieStorage this is being used to store all cookies in this library.

Plug into your application

Note**: Please provide AuthService into your core module.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AuthService } from 'ngx-auth-service';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [ AuthService ],
  bootstrap: [AppComponent]
})
export class AppModule { }

How to use

Inject into your Component or Service.

    constructor(private oAuthService: AuthService) {
    }

AuthService Configure

User can configure some of keys for auth service as per project requirements.

User need to set AuthServiceConstants keys for usages.

Need to set serverUrl and endPoint. This will be used to hit login api using httpService

ServerUrl is host endPoint is api end point

KeysRequiredDefault ValueUsage
headerTokentrueBasicused to send in header for login
accessTokenKeytrueaccTokenused to store access token in cookie
refreshTokenKeytruerefTokenused to store refresh token in cookie
expiresInKeytrueexprInused to store expire time in cookie
loggedInKeytrueloggedInused to check whether user is loggeIn or not from cookie
redirectPathtrue/used for redirecting after system logut
serverUrltruenullused for http request host
logintruenullused for http request for login and refresh token api end point
logouttruenullused for http request for logout api end point
headersfalse{}Provide extra headers for all Http request including multipart request

Object for login

    export class OAuthRequestProto {
      username: string;
      password: string;
      scope: string = 'write';
      grant_type: string = 'password';
      realm: string;
      authType: string;
      refresh_token: string;
    }

Methods

getAccessToken(): string;

    const accessToken: string = oAuthService.getAccessToken();

will return access token which is stored using cookie service in cookie.

setUserLoggedIn(): void;

    oAuthService.setUserLoggedIn();

It will store cookie for loggedIn using loggedInKey from configure constants.

    oAuthService.logoutSystem().subscribe((response) => {
    // to remove all cookie and redirect to page [default '/']
    oAuthService.removeUsersDetailsAndRedirect();
    });
    

logout user from system via api calling and after success remove all cookie value from cookie and redirect to configured page.

refreshToken(): Observable;

    oAuthService.refreshToken().subscribe((response) => {
    oAuthService.storeAccessTokenResponse(
            response.accessToken,
            response.expiresIn, 
            response.refreshToken
            );
    oAuthService.setUserLoggedIn();
    });

to refresh token when access token get expired.

storeAccessTokenResponse(accessToken: string, expiresIn: string, refreshToken: string): void;

    oAuthService.storeAccessTokenResponse(
                    response.accessToken,
                    response.expiresIn, 
                    response.refreshToken
                    );

to store token and expiry details for session.

For more Information

you can contact on kumarganesh088@gmail.com

1.0.2

2 years ago

1.0.1

3 years ago

1.0.0

4 years ago

1.0.5-rc-1

4 years ago