@hemia/auth-sdk 0.0.15 → 0.0.16
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.
- package/dist/hemia-auth-sdk.esm.js +25 -1
- package/dist/hemia-auth-sdk.js +25 -0
- package/dist/types/ioc.d.ts +2 -1
- package/dist/types/services/index.d.ts +1 -0
- package/dist/types/services/oauth.service.d.ts +8 -0
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/oauth-client-response.interface.d.ts +15 -0
- package/dist/types/types/oauth-config.interface.d.ts +4 -0
- package/package.json +1 -1
|
@@ -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 };
|
package/dist/hemia-auth-sdk.js
CHANGED
|
@@ -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;
|
package/dist/types/ioc.d.ts
CHANGED
|
@@ -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;
|
|
@@ -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
|
+
}
|