Skip to content

Introducing Common JWT support for Pod APIs#618

Merged
symphony-mariacristina merged 36 commits intofinos:mainfrom
symphony-mariacristina:commonJwtPod
Jan 14, 2022
Merged

Introducing Common JWT support for Pod APIs#618
symphony-mariacristina merged 36 commits intofinos:mainfrom
symphony-mariacristina:commonJwtPod

Conversation

@symphony-mariacristina
Copy link
Copy Markdown
Contributor

@symphony-mariacristina symphony-mariacristina commented Jan 4, 2022

Ticket

#617

Description

Goal of this implementation is to be able to start using the common JWT to call pod public APIs.
First of all the usage of common jwt can be configured by a configuration property in the application.yaml file.

When the feature is enabled, the Authorization token will be used as header for each Pod call instead of the sessionToken.
To do so, we are programmatically enforcing a new Authentication scheme (OAuthorization) which is in charge of adding the Authorization token in the headers and removing the sessionToken when the feature is enabled.

Being the common jwt token expiration very low respect to the sessionToken, the OAuthSession is going to make sure that before making any Api call with the new Authorization scheme, the common jwt is up to date and in case it expires it is going to be refreshed before.

Checklist

  • Referenced a ticket in the PR title and in the corresponding section
  • Filled properly the description and dependencies, if any
  • Unit tests updated or added
  • Javadoc added or updated
  • Updated the documentation in docs folder

Closes #617

Goal of this implementation is to be able to start using the common JWT to call pod public APIs.
First of all the usage of common jwt can be configured by a configuration property in the application.yaml file.
when the feature is enabled, the Authorization token will be used as header for each Pod call instead of the sessionToken. This is possible thanks to a new ApiClient called BearerEnabledApiClient. When the bot is in common jwt mode enabled we will check the expiration date found in the jwt before making any call. If this date is expired then we eill trigger the refresh token and a new common jwt will be requested and saved in the AuthSession.
Comment thread symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/AuthSession.java Outdated
@thibauult thibauult added this to the 2.6.0 milestone Jan 11, 2022
Missing:
- Check if we can remove AuthSession.refreshAuthToken
- Make refresh bearer token happen before 401
- Finish clean up
Comment thread symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/AuthSession.java Outdated
@symphony-mariacristina symphony-mariacristina marked this pull request as ready for review January 12, 2022 08:55
@symphony-mariacristina symphony-mariacristina requested a review from a team as a code owner January 12, 2022 08:55
…nly + adding test to SymphonyBdkAutoConfigurationTest
Copy link
Copy Markdown
Member

@thibauult thibauult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that will be my last comments :)

Comment on lines +280 to +286
private String[] withEnforcedSecurityScheme(String[] authNames) {
if (authNames == null) {
authNames = new String[0];
}

return Stream.concat(this.enforcedAuthenticationSchemes.stream(), Arrays.stream(authNames)).toArray(String[]::new);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point it think that we will have to create an AbstractApiClient in the symphony-bdk-http-api module to avoid this kind of duplications

Copy link
Copy Markdown
Contributor

@symphony-elias symphony-elias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Copy link
Copy Markdown
Member

@thibauult thibauult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Comment thread symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/AuthSession.java Outdated
Comment thread symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/OAuthSession.java Outdated
Comment thread symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/jwt/JwtHelper.java Outdated
Comment thread symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/OAuthSession.java Outdated
…hSession.java

Co-authored-by: Youri Bonnaffé <63661676+symphony-youri@users.noreply.github.com>
…thSession.java

Co-authored-by: Youri Bonnaffé <63661676+symphony-youri@users.noreply.github.com>
Since common jwt is not yet available for Obo calls if the bot configuration contains an app with the common jwt feature enabled, we are going to fail the bot start up.
To avoid calling the login api to many times, we now first try to refresh the expired jwt by calling the idm/tokens endpoint. if that do not work we then try to refresh all the tokens as usual.
Also AuthSessionCertImpl and AuthSessionImpl have been merged since they were executing the same code
Comment thread docs/configuration.md Outdated
maxIntervalMillis: 10000


commonJwt:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's maybe not even document it for now? as it is not fully supported (OBO, agent)

@symphony-mariacristina symphony-mariacristina merged commit b77d36a into finos:main Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introducing Common jwt support for Pod APIs

4 participants