### File

`projects/app-base-library/src/lib/angular/services/authentication/token-storage.service.ts`

### Index

###### Properties

- Public options

###### Methods

- Public clear
- Public getAccessToken
- Public getRefreshToken
- init
- Public setAccessToken
- Public setRefreshToken

### Methods

Public clear
`clear()`
Defined in projects/app-base-library/src/lib/angular/services/authentication/token-storage.service.ts:51
Remove tokens Returns : `void`

Public getAccessToken
`getAccessToken()`
Defined in projects/app-base-library/src/lib/angular/services/authentication/token-storage.service.ts:19
Get access token Returns : `Observable<string>`

Public getRefreshToken
`getRefreshToken()`
Defined in projects/app-base-library/src/lib/angular/services/authentication/token-storage.service.ts:27
Get refresh token Returns : `Observable<string>`

init
`init(options: )`
Defined in projects/app-base-library/src/lib/angular/services/authentication/token-storage.service.ts:12

Parameters :

Name | Optional
options | no

Returns : `void`

Public setAccessToken
`setAccessToken(token: string)`
Defined in projects/app-base-library/src/lib/angular/services/authentication/token-storage.service.ts:35

Set access token

Parameters :

Name | Type | Optional
token | `string` | no

Returns : `TokenStorage`

Public setRefreshToken
`setRefreshToken(token: string)`
Defined in projects/app-base-library/src/lib/angular/services/authentication/token-storage.service.ts:43

Set refresh token

Parameters :

Name | Type | Optional
token | `string` | no

Returns : `TokenStorage`

### Properties

Public options
`options: `object``
Type : `object`
Default value : `{ accessTokenId: 'accessToken', refreshTokenId: 'refreshToken' }`
Defined in projects/app-base-library/src/lib/angular/services/authentication/token-storage.service.ts:7

    import { Injectable } from '@angular/core';
    import { Observable } from 'rxjs/Observable';

    @Injectable()
    export class TokenStorage {

        public options = {
            accessTokenId: 'accessToken',
            refreshTokenId: 'refreshToken'
        };

        init(options) {
          this.options = options;
        }

      /**
       * Get access token
       */
      public getAccessToken(): Observable<string> {
        const token: string = <string>localStorage.getItem(this.options.accessTokenId);
        return Observable.of(token);
      }

      /**
       * Get refresh token
       */
      public getRefreshToken(): Observable<string> {
        const token: string = <string>localStorage.getItem(this.options.refreshTokenId);
        return Observable.of(token);
      }

      /**
       * Set access token
       */
      public setAccessToken(token: string): TokenStorage {
        localStorage.setItem(this.options.accessTokenId, token);
        return this;
      }

       /**
       * Set refresh token
       */
      public setRefreshToken(token: string): TokenStorage {
        localStorage.setItem(this.options.refreshTokenId, token);
        return this;
      }

       /**
       * Remove tokens
       */
      public clear() {
        localStorage.removeItem(this.options.accessTokenId);
        localStorage.removeItem(this.options.refreshTokenId);
      }
    }

# results matching ""

# No results matching ""