Open M4n1x opened 4 years ago
We need this exact fix aswell, for the same exact reasons
This is especially true when using Nx with libraries :)
Still not working, do you plan to fix this? It is quite limiting and forcing me to use another OIDC library.
I've added a provider with DI injection token & useExisting for the OAuthService dependency, then injected it in the other lib by referencing the injection token.
@steffbeckers do you mind sharing your implementation code snippet or gist?
@steffbeckers do you mind sharing your implementation code snippet or gist?
@ruvan83, the following solution worked for me, not sure if this is a best practice. I've added the following provider to the module where the OAuthModule.forRoot() is imported:
@NgModule({
imports: [
OAuthModule.forRoot()
],
providers: [
{
provide: 'OAUTH_SERVICE',
useExisting: OAuthService
}
]
})
export class AppModule {}
You can now inject the OAuthService in another library (which is used by the app) using the existing instance of the service.
@Injectable()
export class SomeServiceInOtherLib {
constructor(@Inject('OAUTH_SERVICE') private oAuthService: OAuthService) {}
}
For the 'OAUTH_SERVICE' string you could also use an injection token: https://angular.io/api/core/InjectionToken
I hope this works for you 😄
Describe the bug OAuthService cannot be resolved by dependency injection. I have the need to provide a custom wrapper around your API for company specific use cases. Therefore I want to use this library through a self written library.
Angular Project A should use OpenId
MyOpenIdWrapper is a wrapper around this library.
OAuthService is only used within MyOpenIdWrapper and cannot be resolved inside a service in the MyOpenIdWrapper library.
Using this library directly in Angular Project A is no problem.
Stackblitz example Not provided, since it would require a custom library in between.
To Reproduce Steps to reproduce the behavior:
Expected behavior Possibility to use the library through a custom wrapper library.
Desktop (please complete the following information):
Additional context The following change fixes the Problem: Change
to
in oauth-service.ts and remove OAuthService registration from angular-oauth-oidc.module.ts