Skip to content

[typescript-angular2] Allow lazy oauth token refresh (async access_token function) #6486

Closed
@alexrashed

Description

@alexrashed
Description

In case of an OAuth2 implicit flow the current implementation of the Configuration class allows the accessToken to either be a string or a function returning a string (directly). In order to allow a lazy update of the (already expired) access_token using the (still valid) refresh_token the function should get the name of the authorization scheme as well as the necessary scopes and should return an Observable<string>.

export class Configuration {
    ...
    accessToken?: string | ((name: string, scopes?: string[]) => string) => Observable<string>);
    ...
}

This would allow an asynchronous implementation of the accessToken function where the auth server can be requested for a new token.

Swagger-codegen version

2.3.0-SNAPSHOT

Command line used for generation

swagger-codegen-maven-plugin in version 2.3.0-SNAPSHOT for typescript-angular with ngVersion=4

Steps to reproduce

Try to create a Configuration object which lazily refreshes the access_token (when the access_token has expired, but the refresh_token is still valid).

Related issues/PRs

I commented on a PR for the typescript-fetch client suggesting this feature a few weeks ago (this time I mean the angular2 client): #6130 (comment)
This PR also contains the new parameters for the accessToken function for the Typescript-Flow client (but does not return an Observable<string>): Configuration class changes in PR 6130

Suggest a fix/enhancement
  • Change the Configuration class to allow the access_token function to return an Observable<string>
  • Forward the name of the authorization scheme as well as the scope to the access_token function
  • Build the requestOptions asynchronously before executing the http request (flatMap the Observables)

I'm working on a PR right now, I just want to make sure that the feature would be accepted. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions