{"action":"closed","issue":{"url":"https://api.github.com/repos/mbohun/jasig-cas-4.0.x-overlay-template/issues/1","labels_url":"https://api.github.com/repos/mbohun/jasig-cas-4.0.x-overlay-template/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/mbohun/jasig-cas-4.0.x-overlay-template/issues/1/comments","events_url":"https://api.github.com/repos/mbohun/jasig-cas-4.0.x-overlay-template/issues/1/events","html_url":"https://github.com/mbohun/jasig-cas-4.0.x-overlay-template/issues/1","id":107639840,"number":1,"title":"Google OAuth app used by pac4j-1.4.x does NOT work with pac4j-1.7.x","user":{"login":"mbohun","id":1772897,"avatar_url":"https://avatars.githubusercontent.com/u/1772897?v=3","gravatar_id":"","url":"https://api.github.com/users/mbohun","html_url":"https://github.com/mbohun","followers_url":"https://api.github.com/users/mbohun/followers","following_url":"https://api.github.com/users/mbohun/following{/other_user}","gists_url":"https://api.github.com/users/mbohun/gists{/gist_id}","starred_url":"https://api.github.com/users/mbohun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbohun/subscriptions","organizations_url":"https://api.github.com/users/mbohun/orgs","repos_url":"https://api.github.com/users/mbohun/repos","events_url":"https://api.github.com/users/mbohun/events{/privacy}","received_events_url":"https://api.github.com/users/mbohun/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mbohun/jasig-cas-4.0.x-overlay-template/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":{"login":"mbohun","id":1772897,"avatar_url":"https://avatars.githubusercontent.com/u/1772897?v=3","gravatar_id":"","url":"https://api.github.com/users/mbohun","html_url":"https://github.com/mbohun","followers_url":"https://api.github.com/users/mbohun/followers","following_url":"https://api.github.com/users/mbohun/following{/other_user}","gists_url":"https://api.github.com/users/mbohun/gists{/gist_id}","starred_url":"https://api.github.com/users/mbohun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbohun/subscriptions","organizations_url":"https://api.github.com/users/mbohun/orgs","repos_url":"https://api.github.com/users/mbohun/repos","events_url":"https://api.github.com/users/mbohun/events{/privacy}","received_events_url":"https://api.github.com/users/mbohun/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2015-09-22T03:42:44Z","updated_at":"2015-09-23T14:37:21Z","closed_at":"2015-09-23T14:37:21Z","body":"**errors/exceptions:**\r\n\r\nThis one is caused by pointing a `pac4j-1.7.x` based app at `pac4j-1.4.x` Google OAuth endpoint URL:\r\n```\r\nCaused by: org.pac4j.core.exception.TechnicalException: org.scribe.exceptions.OAuthException: Cannot extract an acces token. Response was: {\r\n  \"error\" : \"invalid_grant\",\r\n  \"error_description\" : \"Code was already redeemed.\"\r\n}\r\n```\r\n\r\nThis one is caused by pointing `pac4j-1.7.x` based app at Google OAuth endpoint **without Google+ API being enabled**. (Unlike the `pac4j-1.4.x` (with it's old Google OAuth endpoint), `pac4j-1.7.x` (with it's new Google OAuth endpoint) **does require Google+ API to be enabled** in the Google OAuth app configuration in https://console.developers.google.com `APIs&auth -> APIs`).\r\n```\r\n2015-09-22 06:29:40,587 ERROR [org.pac4j.oauth.client.BaseOAuthClient] - <Failed to get data, code : 403 / body : {\r\n \"error\": {\r\n  \"errors\": [\r\n   {\r\n    \"domain\": \"usageLimits\",\r\n    \"reason\": \"accessNotConfigured\",\r\n    \"message\": \"Access Not Configured. The API (Google+ API) is not enabled for your project. Please use the Google Developers Console to update your configuration.\",\r\n    \"extendedHelp\": \"https://console.developers.google.com\"\r\n   }\r\n  ],\r\n  \"code\": 403,\r\n  \"message\": \"Access Not Configured. The API (Google+ API) is not enabled for your project. Please use the Google Developers Console to update your configuration.\"\r\n }\r\n}\r\n>\r\n``` \r\n\r\nThe Google OAuth endpoint URLs are diff (changed between pac4j-1.4.x and pac4j-1.7.x):  \r\n[pac4j-1.4.x](https://github.com/pac4j/pac4j/blob/1.4.x/pac4j-oauth/src/main/java/org/pac4j/oauth/client/Google2Client.java#L96):\r\n```java\r\n    @Override\r\n    protected String getProfileUrl() {\r\n        return \"https://www.googleapis.com/oauth2/v2/userinfo\";\r\n    }\r\n```\r\n[pac4j-1.7.x](https://github.com/pac4j/pac4j/blob/1.7.x/pac4j-oauth/src/main/java/org/pac4j/oauth/client/Google2Client.java#L95):\r\n```java\r\n    @Override\r\n    protected String getProfileUrl(final Token accessToken) {\r\n        return \"https://www.googleapis.com/plus/v1/people/me\";\r\n    }\r\n```\r\nThat is the reason why a Google OAuth app setup for `pac4j-1.4.x` does **NOT** simply/automatically work with with `pac4j-1.7.x`.\r\n\r\nThe last problem/error was caused by the fact that the internal representation/structure of `org.pac4j.oauth.profile.google2.Google2Profile` changed between `pac4j-1.4.x` and `pac4j-1.7.x`, and the parsing/extraction of email, first name, last name fields failed:\r\n```\r\n2015-09-22 06:39:37,223 DEBUG [org.jasig.cas.support.pac4j.authentication.handler.support.ALAClientAuthenticationHandler] - <userProfile : <Google2Profile> | id:\r\n 105600676538699036821 | attributes: {image.url=https://lh4.googleusercontent.com/-LkKJRNzwc_U/AAAAAAAAAAI/AAAAAAAABQE/oocuizk5n0s/photo.jpg?sz=50, name.familyNa\r\nme=Bohun, gender=MALE, emails=[{\"value\":\"martin.bohun@gmail.com\",\"type\":\"account\"}], language=en, name.givenName=Martin, displayName=Martin Bohun, access_token=y\r\na29.9gG_EVUW4bbgOXfK5-zim50NFvYTBZPesI_03EYyUx7cXBYyBq7s83dodLP53lgOy4WO, url=https://plus.google.com/+MartinBohun} | roles: [] | permissions: [] | isRemembered:\r\n false |>\r\n2015-09-22 06:39:37,224 DEBUG [au.org.ala.cas.AttributeParser] - <processing/parsing profile: Google2Profile>\r\n2015-09-22 06:39:37,224 DEBUG [au.org.ala.cas.AttributeParser] - <parsing: Google2Profile, attributes: {image.url=https://lh4.googleusercontent.com/-LkKJRNzwc_U/AAAAAAAAAAI/AAAAAAAABQE/oocuizk5n0s/photo.jpg?sz=50, name.familyName=Bohun, gender=MALE, emails=[{\"value\":\"martin.bohun@gmail.com\",\"type\":\"account\"}], language=en, name.givenName=Martin, displayName=Martin Bohun, access_token=ya29.9gG_EVUW4bbgOXfK5-zim50NFvYTBZPesI_03EYyUx7cXBYyBq7s83dodLP53lgOy4WO, url=https://plus.google.com/+MartinBohun}>\r\n2015-09-22 06:39:37,224 DEBUG [org.jasig.cas.support.pac4j.authentication.handler.support.ALAClientAuthenticationHandler] - <email : null>\r\n2015-09-22 06:39:37,225 DEBUG [org.jasig.cas.support.pac4j.authentication.handler.support.ALAClientAuthenticationHandler] - <Invalid email : null, authentication aborted!>\r\n```\r\n\r\n**The moral of the story:** create, resp. add automated (most likely REST based) test, that will be run as part of the travis-ci build, so it will automatically pick up this type of annoyances ASAP."}}