Skip to content

Being able to provide an abstract HttpClient #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
philly-vanilly opened this issue Jul 13, 2020 · 2 comments
Open

Being able to provide an abstract HttpClient #888

philly-vanilly opened this issue Jul 13, 2020 · 2 comments
Labels
feature-request Improvements and additions to the library.

Comments

@philly-vanilly
Copy link

philly-vanilly commented Jul 13, 2020

Is your feature request related to a problem? Please describe.
I want to be able to use @ionic-native/http/ngx with HTTPS pinning in a mobile/Ionic app.

Describe the solution you'd like
By default, the plugin should still use Angular HttpClient, but there should be an option to replace it. I am thinking of something like:

export interface OAuthHttpClient {
   // options should probably have an own interface; too bad node_modules/@angular/common/http/http.d.ts does not provide one
    get<T>(endpoint: string, options: any): Observable<T>;
    // post and other methods used in the lib as well
}

And then, in the lib-consumer you could do something like:

import { OAuthHttpClient } from 'angular-oauth2-oidc';
import { HTTP } from "@ionic-native/http/ngx";

@Injectable({providedIn: "root"})
export class MyOwnHttpClient implements OAuthHttpClient {
    constructor(private nativeHttp: HTTP){}

    get<T>(endpoint: string, options: any): Observable<T> {
        await this.nativeHttp.setServerTrustMode("pinned");
        ...
        this.nativeHttp.sendRequest(endpoint, {
                    method: "get",
                    params: options.params,
                    headers: options.headers,
                    responseType: options.responseType,
                })
    }
}

and set it in the AuthConfig or do sth like this (but I think this would break your backward-compatibility):

{
    provide: OAuthHttpClient,
    useClass: MyOwnHttpClient // this way you could remote "providedIn: root"
}

Describe alternatives you've considered
Using an Ionic specific lib...

Additional context
Nothing for now

@jeroenheijmans jeroenheijmans added the feature-request Improvements and additions to the library. label Jul 13, 2020
@philly-vanilly
Copy link
Author

Since the Angular HtpClient is huge, one would need to extract only the methods into an abstract interface which are used in oauth-service.ts, e.g.

this.http.get<OidcDiscoveryDoc>(fullUrl).subscribe(
this.http.get(this.jwksUri).subscribe(
this.http.get<UserInfo>(this.userinfoEndpoint, { headers })
this.http.post<TokenResponse>(this.tokenEndpoint, params, { headers })
...

should be covered

@wellwoller
Copy link

Any progress on this issue yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Improvements and additions to the library.
Projects
None yet
Development

No branches or pull requests

3 participants