# @kimaya-hybrid/ngx-auth-service

> This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.1.0.

Latest version **1.0.2** (published 2023-01-10) · 0 weekly downloads

## Install

```sh
npm install @kimaya-hybrid/ngx-auth-service
pnpm add @kimaya-hybrid/ngx-auth-service
yarn add @kimaya-hybrid/ngx-auth-service
bun add @kimaya-hybrid/ngx-auth-service
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-01-10 |
| First published | 2023-01-10 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 241.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ganesh.kumar |

## Links

- npm: https://www.npmjs.com/package/@kimaya-hybrid/ngx-auth-service
- npm.io page: https://npm.io/package/@kimaya-hybrid/ngx-auth-service

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0

## Recent versions

- 1.0.2 (latest) — 2023-01-10

## README

# AuthHandler

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.1.0.

## How Install
    npm install @kimaya/ngx-auth-service

#### Dependency 
<code>*You need to install dependencies manually*</code> 

[CookieStorage](https://github.com/gns088/storage-service)
this is being used to store all cookies in this library.

## Plug into your application
Note**: Please provide <code>AuthService</code> 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 <code>Component</code> or <code>Service</code>.
        
        constructor(private oAuthService: AuthService) {
        }

 ## AuthService Configure
 User can configure some of keys for auth service as per project requirements.
   
 User need to set <code>AuthServiceConstants</code> keys for usages.
 
 *Need to set <code>serverUrl</code> and <code>endPoint</code>. This will be used to hit login api using httpService*
 
 <code>ServerUrl is host </code><br>
 <code>endPoint is api end point</code>
 
 | Keys | Required | Default Value| Usage|
 |-------------|-------------|-----|-----|
 | headerToken | true |Basic  | used to send in header for login  |
 | accessTokenKey | true |accToken | used to store access token in cookie |
 | refreshTokenKey | true |refToken | used to store refresh token in cookie |   
 | expiresInKey | true |exprIn | used to store expire time in cookie |   
 | loggedInKey | true |loggedIn | used to check whether user is loggeIn or not from cookie |   
 | redirectPath | true |/ | used for redirecting after system logut | 
 | serverUrl | true | null | used for http request host |   
 | login | true | null | used for http request for login and refresh token api end point |
 | logout | true | null | used for http request for logout api end point |
 | headers | false | {} | 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.
<hr>
        
#### getRefreshToken(): string;
        const refreshToken: string = oAuthService.getRefreshToken();
will return refresh token which is stored using cookie service in cookie.        
<hr>

        
#### setUserLoggedIn(): void;
        oAuthService.setUserLoggedIn();
It will store cookie for loggedIn using `loggedInKey` from configure constants.     
<hr>
        
#### isLoggedIn(): boolean;
        const isLoggedIn: boolean = oAuthService.isLoggedIn();
check whether user is loggedIn or not.        
<hr>
        
#### logoutSystem(): Observable<Object>;

        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.        
<hr>
  
#### login(object: OAuthRequestProto): Observable<any>;
        oAuthService.login(object).subscribe((response) => {
            oAuthService.storeAccessTokenResponse(
            response.accessToken,
            response.expiresIn, 
            response.refreshToken
            );
            oAuthService.setUserLoggedIn();
        });
to login into system.      
<hr>

#### refreshToken(): Observable<any>;
        oAuthService.refreshToken().subscribe((response) => {
        oAuthService.storeAccessTokenResponse(
                response.accessToken,
                response.expiresIn, 
                response.refreshToken
                );
        oAuthService.setUserLoggedIn();
        });
to refresh token when access token get expired.      
<hr>

#### storeAccessTokenResponse(accessToken: string, expiresIn: string, refreshToken: string): void;
        oAuthService.storeAccessTokenResponse(
                        response.accessToken,
                        response.expiresIn, 
                        response.refreshToken
                        );
to store token and expiry details for session.      
<hr>

## For more Information 
you can contact on <code>kumarganesh088@gmail.com</code>

---
_Source: https://npm.io/package/@kimaya-hybrid/ngx-auth-service · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
