Skip to content
This repository has been archived by the owner on Mar 13, 2020. It is now read-only.

Changing the scopes break everything #9

Closed
andreydeineko opened this issue Sep 20, 2016 · 2 comments
Closed

Changing the scopes break everything #9

andreydeineko opened this issue Sep 20, 2016 · 2 comments
Assignees

Comments

@andreydeineko
Copy link

andreydeineko commented Sep 20, 2016

SCOPES = %w(openid profile).freeze # removed https://outlook.office.com/mail.read

def get_email_from_id_token(id_token)
  token_parts   = id_token.split('.')
  leftovers     = token_parts[1].length.modulo(4)
  encoded_token = token_parts[1] += leftovers == 2 ? '==' : '='
  decoded_token = Base64.decode64(encoded_token)
  JSON.parse(decoded_token)['preferred_username']
end

def get_token_from_code(auth_code) # throws the below exception: OAuth2::Error - :
  client.auth_code.get_token(auth_code, redirect_uri: authorize_url, scope: SCOPES.join(' '))
end
OAuth2::Error - :
{"token_type":"Bearer","refresh_token":"long-refresh-token","id_token":"even-longer-id-token"}

BUT When I take the id_token and use it in

get_email_from_id_token(id_token)

it works. How do I make correct it? Why it throws an error?

@jasonjoh
Copy link
Owner

Not sure, I'd really have to see the request/response on the wire. It maybe that Azure returns an error if you have no resource scope, or it may be that the OAuth library doesn't like the response.

@jasonjoh jasonjoh self-assigned this Nov 29, 2016
@jasonjoh
Copy link
Owner

Seems to be an error in the oauth2 gem. The Azure endpoint is only returning an ID token here, since the scopes you included only get you an ID token. This is correct behavior. However, it looks like the gem expects an access token. See oauth-xx/oauth2#243.

Closing this issue as it's not really in the scope of this tutorial.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants