Skip to content

Instantly share code, notes, and snippets.

@abadongutierrez
Last active February 1, 2021 06:37
Show Gist options
  • Save abadongutierrez/97927a57b2e78a0d157d9cd2fb9e0961 to your computer and use it in GitHub Desktop.
Save abadongutierrez/97927a57b2e78a0d157d9cd2fb9e0961 to your computer and use it in GitHub Desktop.
Micronaut Tutorial - Login with Microsoft - MicrosoftGraphApiClient class
package com.jabaddon.tutorials.micronaut.loginwithmicrosoft;
import io.micronaut.core.type.Argument;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.MutableHttpRequest;
import io.micronaut.http.client.RxHttpClient;
import io.micronaut.http.uri.UriBuilder;
import io.reactivex.Flowable;
import io.reactivex.Single;
import javax.inject.Singleton;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@Singleton
public class MicrosoftGraphApiClient {
private final RxHttpClient httpClient;
private final URI uri;
public MicrosoftGraphApiClient() throws MalformedURLException {
httpClient = RxHttpClient.create(new URL("https://graph.microsoft.com"));
uri = UriBuilder.of("/v1.0/me").build();
}
Single<MicrosoftUser> myProfile(String authorization) {
MutableHttpRequest<?> req = HttpRequest.GET(uri);
req.bearerAuth(authorization);
Flowable<MicrosoftUser> flowable = httpClient.retrieve(req, Argument.of(MicrosoftUser.class));
return flowable.singleOrError();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment