Skip to content
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

Added OkHttpClient API call for auth check #9

Conversation

harveymmaunders
Copy link
Contributor

Added API call to help check authorisation. Don't need to configure retrofit service as just uses an OkHttpClient to call the API and print response code and body.

Added logging debugs for JWTs. They are also decoded using JWT library if more information is needed.

In the tests, changed the MOCK_TOKEN to a fake JWT that can be decoded.

@harveymmaunders harveymmaunders requested a review from a team as a code owner January 3, 2025 12:38
@harveymmaunders harveymmaunders changed the title Added easy API call Added OkHttpClient API call for auth check Jan 3, 2025
builder.header("Authorization", "Bearer " + msClientAuthTokenService.getAccessToken());
String token = msClientAuthTokenService.getAccessToken();
logger.debug("Retrieved token");
DecodedJWT jwt = JWT.decode(token);
Copy link
Member

Choose a reason for hiding this comment

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

is this JWT actually used anywhere or logged? might be worth highlighting that this is optional (and the dependency that is needed for this)

@@ -38,6 +55,8 @@ public class MsRetrofitWrapper {
*/
public MsRetrofitWrapper(String url, Level logLevel) throws Exception {
this.msClientAuthTokenService = new MsClientAuthTokenService(MICROPROFILE_CONFIG_SERVICE);
this.url = url;
this.logLevel = logLevel;
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed on the constructor? is there any way people can omit having to set this explicitly and instead do via microprofile config? (e.g. in Spring, you would rarely never set a log level directly in code)

Copy link
Member

Choose a reason for hiding this comment

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

Also, is this like a debug/info/warn style level or is it more detailed/specific?

@@ -94,4 +115,16 @@ public Retrofit getRetrofit() {
public <T> T createService(Class<T> serviceInterface) {
return this.getRetrofit().create(serviceInterface);
}

public void checkAuthorisation(String apiEndpoint) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Javadoc on this method to explain what it's for

@harveymmaunders harveymmaunders deleted the java-rest-auth-check branch January 10, 2025 11:46
harveymmaunders added a commit that referenced this pull request Jan 17, 2025
…samples/python/rest/black-24.10.0

pip-rest: bump black from 24.3.0 to 24.10.0 in /client-samples/python/rest
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.

2 participants