@innotec/auth-plugin
v5.2.22
Published
The plugin to authorize on innotec infrastructure
Downloads
315
Keywords
Readme
Innotec Auth Plugin
The Innotec-Auth-Plugin is designed to handle all authentication processes for applications where's conntected to the innotec v2 infrastructure. Theses plugin provides different authentication processes:
- Authentication over authentication providers (Google, PayPal, Facebook ...)
- Authentication over the Innotec V2 Infrastructure (Authentication by username and password)
With this module its easy to connect the infrastructure.
Installation
NOTE: please use npm 3.*
((sudo) npm i -g npm@3
)
npm i --save --save-exact @innotec/auth-plugin
Note!
The npm Module innotec-auth-plugin
is deprecated. All Modules are provided in root of @innotec
Import in your app module
You can import the module in your Application with:
import { InnotecAuthPlugin } from "innotec-auth-plugin";
Integration Steps
First
At first you must set your personal options of your app. To set this options call the initAuth
Service by APP_INITIALIZER in app.module:
import { InnotecAuthPluginModule, InitAuth } from "../../index";
export function init_app(init: InitAuth): () => Promise<any> {
return (): Promise<any> => {
return new Promise((resolve, reject) => {
(async () => {
let options = {
companyLogo: "http://yourLogoURL", // You can define a own logo of your companyLogo. Default is the logo of the Innotec Company
clientId: "Innotec Client ID", // Your clientId from Innotec
clientSecret: "Innotec Client Secret",// Your clientSecret from Innotec
facebook_clientId: "abc", // The Facebook Client_ID for OAuth
google_clientId: "abc", // The Google Client_ID for OAuth
paypal_clientId: "abc", // The PayPal Client_ID for OAuth
forgotPassurl: "http://..." // The Url of the forgot password
endpoint: "live", // Switch for the endpoints. Sandbox is comming soon. live is default.
newAccountUrl: "url", // Defines the url where the user can be register... Default is "https://account.v2.werbasinnotec.com/newaccount"
closeable: true // Boolen to define if the loginwindow is closeable
};
await init.module(options);
resolve();
})();
});
};
}
NgModule({
imports: [
InnotecAuthPluginModule,
.
.
],
declarations: [
.
.
.
],
providers: [
JwtHelper,
{
provide: APP_INITIALIZER,
useFactory: init_app,
deps: [ InitAuth ],
multi: true,
}
],
bootstrap: [AppComponent]
})
export class AppModule {
constructor() {}
}
Second
At next you can import the loginfield in your login page:
<login-field></login-field>
The loginfield provides all necessary services to connect the innotec infrastructure. You can import this field as mat-dialog
, too.
Third
To check the loginstate you can call the auth service:
import { CheckAuthStatus } from 'innotec-auth-plugin';
export class YoUrClAsSs {
constructor (private auth: CheckAuthStatus) {
}
public yourService() {
this.auth.check(); // returns true or false
}
}
You can subscribe the variable also:
this.auth.isLoggedIn().subscribe((state) => {
this.isLoggedIn = state
});
Additional services
CheckAuthStatus:
- logout(): User will logged out - Cookie will deleted.
- getTokenInfo(): Will response all tokeninfo. Ex. userObj.gravatarURL is the users picture
UserRights
- validateRightTopic([systemId], [RightTopic], [orgaId], [minApiVersion])
With this method it's possible to validate a right-topic by systemId, orgaId and minApiVersion. The property minApiVersion
is not required. When it's defined, the method will check the defined Version to the backend. Is the backendVersion greater or equal the minApiVersion
the function will return true. (When the user has the right by the topic)
- getAuthorizedSystems()
This method will response an array with all authorized systems and entrypoints.
InformationService
getUserInfos() This method will response the complete userObject where's saved in the cloud backend system.
getOrgaInfos(systemId) This method will response the complete OrganizationObject by the called systemId
Store the user-information into electron
With default javascript methods are not possible to store cookies into the chromium extension of electron. To enable the autologin feature / storing user information it's neccessary to save the information by the ipc-renderer module of electron.
Flow
Subscribe the Cookieservice events in app.module.ts of your electron App
import { CookieService } from '@innotec/auth-plugin';
.
.
.
ngOnInit() {
this.cookie.observe().subscribe(data => {
// data = { name: <nameofcookie>, value: <valueofcookie>, status: 'NEW || DELETE' }
// Write the information of data everywhere.. :-)
});
}
Write the object from the observeable into the authentication plugin on startup (APP_INITIALIZER)
import { InitAuth } from '@innotec/auth-plugin';
.
.
.
setConfiguration() {
this.configObject = ....
this.cookieObject = // Load the object from your IPC Renderer
.
.
.
this.init(this.configObject, this.cookieObject);
}
}