sso-authorization-oidc-client
TypeScript icon, indicating that this package has built-in type declarations

3.1.1 • Public • Published

Simple Single sign-on Authorization using oidc-client and Identity Server /ავტორიზაცია oidc-client-ის გამოყენებით

angular 6

Benefits:

  1. Built in APP_INITILIZER, when angular application starts, It checks auhtorization.
  2. After authorization redirects to start URL. for example: If you aren't authorized and enter to this route http://localhost:4200/test , after authorization redirects same URL
  3. Interseptor which checks errors 401 from backend.
  4. Automaticaly attach bearer token each request
  5. Flexible to use main oidc-client funtions
  6. Authomatic SigneOut, when user signe out one site all site which use this library authomiaticaly SigneOut
  7. Easy Config management

Library contains/ბიბლიოთეკას მოყვება:
a. AuthorizationInterceptor - build in auhtorization interseptor, which checks error code 401 /ეს თვითონ მოდულშია ჩაშებული, ამოწმებს 401-ზე და არედირექტებს Identity-ს URL-ზე, რომელიც კონფიგში იქნება გაწერილი.
b. AuthorizationGuardService - Route guard / პროექტში უნდა route-ებში უნდა გაიწეროს ეს Guard-ი.
c. AuthorizationService - Usable oidc-client library and custom functions / აქ არის მეთოდები რომელსაც იყენებს მოდული.

Usage/მოხმარების წესი:

  1. Import Library and pass config file. install oidc-client /დააიმპორტეთ ბიბლიოთეკა და გადაეცით კონფიგი, დააინსტალირეთ oidc-client-ი
import { AuthorizationModule } from 'sso-authorization-oidc-client';
//OR
import { AuthorizationModule } from 'sso-authorization-oidc-client/src/lib/authorization.module';
 
@NgModule({
  declarations: [
    AppComponent,
    ....
  ],
  imports: [
    BrowserModule,
    AuthorizationModule.forRoot(`assets/config${environment.production ? '.prod' : ''}.json`)
    .....
  ],
  providers: [
      ...
  ]
  bootstrap: [AppComponent]
})
export class AppModule {}
 
  1. Config example /კონფიგი (config.json) უნდა გამოიყურებოდეს ასე:
{
  ....
"authorization": {
    "stsAuthority": "https://demo.identityserver.io/",
    "clientId": "implicit",
    "clientRoot": "http://localhost:4200/",
    "clientScope": "openid profile",
    "responseType": "id_token token",
    "scope": "openid profile",
    "htmlFilePath": "assets",
    "accessTokenExpiringNotificationTime": 100,
    "clockSkew": 500,
    "needAutoLogout": false,
    "autoLogoutTime": 900, //  in seconds
    "checkStorageTime": 10 //  in seconds
  }
  ....
}
  1. assets folder must contains this .js file with name - "oidc-client.js" /assets უნდა ეგდოს .js ფაილი "oidc-client.js" - რომელიც შეგიძლიათ წამოიღოთ: https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.5.2/oidc-client.js

  2. assets folder must contains 2 HTML files /assets ფოლდერში (ან შეგიძლიათ შეცვალოთ კონფიგში ფოლდერის სახელი - "htmlFilePath") უნდა არსებობდეს 2 ცალი HTML ფაილი:

    a. signin-callback.html

    <script src="oidc-client.js"></script>
    <script>
        new Oidc.UserManager();
      var mgr = new Oidc.UserManager().signinRedirectCallback().then(function (user) {
            window.location.href = user.state;
        }, error => {
            console.error(error);
        });
    </script> 

    b. silent-callback.html

    <script src="oidc-client.js"></script>
    <script>
        var mgr = new Oidc.UserManager();
      mgr.signinSilentCallback().catch(error => {
            console.error(error);
        });
    </script> 

Package Sidebar

Install

npm i sso-authorization-oidc-client

Weekly Downloads

0

Version

3.1.1

License

MIT

Unpacked Size

439 kB

Total Files

41

Last publish

Collaborators

  • avto_key