oltu-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jasha Joachimsthal <ja...@apache.org>
Subject Re: Microsoft OAuth2 Question
Date Fri, 09 Jan 2015 07:14:51 GMT
Hi,

My experience is that you cannot just copy-paste the implementation if
you connect with the big public oAuth providers. Most of them have
their own quirks. The following code works for me to get a profile of
a Microsoft account.

Substitute the clientId, clientSecret and redirectUri parameters with
the ones you have configured at Microsoft and handle the state
parameter properly. The scope wl.signin is the minimal scope at
Microsoft.

Authorization request:

OAuthClientRequest oAuthClientRequest = OAuthClientRequest
    .authorizationProvider(OAuthProviderType.MICROSOFT)
    .setClientId("myClientId")
    .setResponseType(OAuth.OAUTH_CODE)
    .setState("myStateValue")
    .setScope("wl.signin")
    .setRedirectURI("https://myapplication.example.com/redirect")
    .buildQueryMessage();

String authzLocation = oAuthClientRequest.getLocationUri()


Get AccessToken:

String getAccessToken(final OAuthAuthzResponse oar)
    throws OAuthSystemException, OAuthProblemException {
  final String code = oar.getCode();
  final OAuthClientRequest oAuthClientRequest = OAuthClientRequest
      .tokenProvider(OAuthProviderType.MICROSOFT)
      .setGrantType(GrantType.AUTHORIZATION_CODE)
      .setClientId("myClientId")
      .setClientSecret("myClientSecret")
      .setRedirectURI("https://myapplication.example.com/redirect")
      .setCode(code)
      .buildBodyMessage();

  final OAuthAccessTokenResponse accessTokenResponse =
oAuthClient.accessToken(oAuthClientRequest);
  return accessTokenResponse.getAccessToken();
}

Get Profile:
final OAuthClientRequest bearerClientRequest = new
OAuthBearerClientRequestBuilder("https://apis.live.net/v5.0/me")
    .setAccessToken(accessToken)
    .buildQueryMessage();

return getoAuthClient().resource(bearerClientRequest,
OAuth.HttpMethod.GET, OAuthResourceResponse.class);

Regards,

Jasha

On 8 January 2015 at 22:41, Tiburtius, Ashwanth [IWD]
<Ashwanth.Tiburtius@iwd.iowa.gov> wrote:
> Hi,
>
>
>
> I am doing a poc to use Apache Oltu for user authentication against Google,
> Microsoft and Yahoo. I was able to successfully use the client demo provided
> by Apache Oltu to authenticate a user in Google using gmail credentials and
> also retrieve user information. But I am running into issues while trying to
> do the same for Microsoft. Following are the details I have entered but I
> keep getting the error “Error: Incorrect parameters: Redirect URI” even
> though the redirect uri matches the one configured in the API settings in
> Microsoft Development Center. This could be a Microsoft question but I would
> highly appreciate any help that you can provide. Google was quit straight
> forward to setup and execute but Microsoft is confusing to say the least.
> Hoping Apache Oltu would make life easier.
>
>
>
> Requested Access Scope: wl.signin
>
> End-User Authorization URL: https://login.live.com/oauth20_authorize.srf
>
> Token Endpoint: https://login.live.com/oauth20_token.srf
>
> Client ID: <Correct value entered>
>
> Client Secret: <Correct value entered>
>
> Redirect URI: http://iwd.gov/profile/register (This is the value entered in
> the API settings)
>
>
>
> Thanks,
>
> Jude.
>
> Iowa Workforce Development – IT | 1000 E Grand Ave, Des Moines, IA  50319
>
> (515) 281-3378 | Ashwanth.Tiburtius@iwd.iowa.gov
>
>

Mime
View raw message