@hemia/auth-sdk 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -402,7 +402,7 @@ let AuthSDKController = class AuthSDKController {
402
402
  res.cookie('auth_flow', JSON.stringify(tempState), {
403
403
  httpOnly: true,
404
404
  secure: process.env.NODE_ENV === 'production',
405
- maxAge: 300000 // 5 min
405
+ maxAge: 7 * 24 * 60 * 60 * 1000 // 7 dias
406
406
  });
407
407
  res.redirect(loginUrl);
408
408
  }
@@ -546,6 +546,22 @@ AuthSDKController = __decorate([
546
546
  __metadata("design:paramtypes", [AuthService])
547
547
  ], AuthSDKController);
548
548
 
549
+ let OAuthService = class OAuthService {
550
+ constructor(oauthConfig, networkServices) {
551
+ this.oauthConfig = oauthConfig;
552
+ this.networkServices = networkServices;
553
+ }
554
+ async getByClientId(clientId) {
555
+ const url = `${this.oauthConfig.getByClientIdUrl}/${clientId}`;
556
+ const response = await this.networkServices.get(url);
557
+ return response.data.data;
558
+ }
559
+ };
560
+ OAuthService = __decorate([
561
+ injectable(),
562
+ __metadata("design:paramtypes", [Object, HMNetworkServices])
563
+ ], OAuthService);
564
+
549
565
  class AuthCacheAdapter {
550
566
  constructor(externalCache) {
551
567
  this.externalCache = externalCache;
@@ -577,5 +593,13 @@ const authPlugin = (config, cacheFactory, options) => {
577
593
  }
578
594
  };
579
595
  };
596
+ const oauthPlugin = (config) => {
597
+ return async (container) => {
598
+ container.bind(OAuthService).toDynamicValue((context) => {
599
+ const network = new HMNetworkServices(config.baseUrl);
600
+ return new OAuthService(config, network);
601
+ }).inSingletonScope();
602
+ };
603
+ };
580
604
 
581
- export { AUTH_SERVICE_ID, AuthSDKController, AuthService, InvalidTokenFormatError, SessionError, SessionExpiredError, SessionInvalidError, SessionNotFoundError, TokenRefreshFailedError, authPlugin };
605
+ export { AUTH_SERVICE_ID, AuthSDKController, AuthService, InvalidTokenFormatError, OAuthService, SessionError, SessionExpiredError, SessionInvalidError, SessionNotFoundError, TokenRefreshFailedError, authPlugin, oauthPlugin };
@@ -404,7 +404,7 @@ exports.AuthSDKController = class AuthSDKController {
404
404
  res.cookie('auth_flow', JSON.stringify(tempState), {
405
405
  httpOnly: true,
406
406
  secure: process.env.NODE_ENV === 'production',
407
- maxAge: 300000 // 5 min
407
+ maxAge: 7 * 24 * 60 * 60 * 1000 // 7 dias
408
408
  });
409
409
  res.redirect(loginUrl);
410
410
  }
@@ -548,6 +548,22 @@ exports.AuthSDKController = __decorate([
548
548
  __metadata("design:paramtypes", [exports.AuthService])
549
549
  ], exports.AuthSDKController);
550
550
 
551
+ exports.OAuthService = class OAuthService {
552
+ constructor(oauthConfig, networkServices) {
553
+ this.oauthConfig = oauthConfig;
554
+ this.networkServices = networkServices;
555
+ }
556
+ async getByClientId(clientId) {
557
+ const url = `${this.oauthConfig.getByClientIdUrl}/${clientId}`;
558
+ const response = await this.networkServices.get(url);
559
+ return response.data.data;
560
+ }
561
+ };
562
+ exports.OAuthService = __decorate([
563
+ inversify.injectable(),
564
+ __metadata("design:paramtypes", [Object, networkServices.HMNetworkServices])
565
+ ], exports.OAuthService);
566
+
551
567
  class AuthCacheAdapter {
552
568
  constructor(externalCache) {
553
569
  this.externalCache = externalCache;
@@ -579,6 +595,14 @@ const authPlugin = (config, cacheFactory, options) => {
579
595
  }
580
596
  };
581
597
  };
598
+ const oauthPlugin = (config) => {
599
+ return async (container) => {
600
+ container.bind(exports.OAuthService).toDynamicValue((context) => {
601
+ const network = new networkServices.HMNetworkServices(config.baseUrl);
602
+ return new exports.OAuthService(config, network);
603
+ }).inSingletonScope();
604
+ };
605
+ };
582
606
 
583
607
  exports.AUTH_SERVICE_ID = AUTH_SERVICE_ID;
584
608
  exports.InvalidTokenFormatError = InvalidTokenFormatError;
@@ -588,3 +612,4 @@ exports.SessionInvalidError = SessionInvalidError;
588
612
  exports.SessionNotFoundError = SessionNotFoundError;
589
613
  exports.TokenRefreshFailedError = TokenRefreshFailedError;
590
614
  exports.authPlugin = authPlugin;
615
+ exports.oauthPlugin = oauthPlugin;
@@ -1,8 +1,9 @@
1
1
  import { ResolutionContext } from "inversify";
2
- import { IAuthConfig } from "./types";
2
+ import { IAuthConfig, IOAuthConfig } from "./types";
3
3
  import { IHemiaCacheService } from "./adapters";
4
4
  import { Plugin } from "@hemia/common";
5
5
  export type CacheFactory = (context: ResolutionContext) => Promise<IHemiaCacheService> | IHemiaCacheService;
6
6
  export declare const authPlugin: (config: IAuthConfig, cacheFactory: CacheFactory, options: {
7
7
  basePath: string;
8
8
  }) => Plugin;
9
+ export declare const oauthPlugin: (config: IOAuthConfig) => Plugin;
@@ -1 +1,2 @@
1
1
  export * from "./auth.service";
2
+ export * from "./oauth.service";
@@ -0,0 +1,8 @@
1
+ import { HMNetworkServices } from "@hemia/network-services";
2
+ import { IOAuthConfig, OAuthClientResponse } from "../types";
3
+ export declare class OAuthService {
4
+ private readonly oauthConfig;
5
+ private readonly networkServices;
6
+ constructor(oauthConfig: IOAuthConfig, networkServices: HMNetworkServices);
7
+ getByClientId(clientId: string): Promise<OAuthClientResponse | undefined>;
8
+ }
@@ -10,3 +10,5 @@ export * from "./standard-claims.interface";
10
10
  export * from "./session-data.interface";
11
11
  export * from "./session-storage.interface";
12
12
  export * from "./session-access.interface";
13
+ export * from "./oauth-config.interface";
14
+ export * from "./oauth-client-response.interface";
@@ -0,0 +1,15 @@
1
+ export interface OAuthClientResponse {
2
+ id: string;
3
+ clientId: string;
4
+ name: string;
5
+ type: string;
6
+ logoUri: string;
7
+ grantTypes: string[];
8
+ isActive: boolean;
9
+ redirectUris: string[];
10
+ allowedScopes: string[];
11
+ allowedAudiences: string[];
12
+ createdAt?: Date;
13
+ updatedAt?: Date;
14
+ productId?: string;
15
+ }
@@ -0,0 +1,4 @@
1
+ export interface IOAuthConfig {
2
+ baseUrl: string;
3
+ getByClientIdUrl: string;
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemia/auth-sdk",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Hemia SDK for authentication",
5
5
  "main": "dist/hemia-auth-sdk.js",
6
6
  "module": "dist/hemia-auth-sdk.esm.js",