{"action":"created","comment":{"url":"https://api.github.com/repos/nuxeo/nuxeo/pulls/comments/82574136","pull_request_review_id":3471690,"id":82574136,"diff_hunk":"@@ -0,0 +1,165 @@\n+/*\n+ * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ *\n+ * Contributors:\n+ *     Gabriel Barata <gbarata@nuxeo.com>\n+ */\n+package org.nuxeo.ecm.restapi.server.jaxrs;\n+\n+import com.google.api.client.auth.oauth2.Credential;\n+import org.codehaus.jackson.map.ObjectMapper;\n+\n+import javax.servlet.http.HttpServletResponse;\n+import javax.ws.rs.core.Response.Status;\n+import javax.ws.rs.core.Response.StatusType;\n+\n+import org.nuxeo.ecm.automation.server.jaxrs.RestOperationException;\n+import org.nuxeo.ecm.core.api.DocumentModel;\n+import org.nuxeo.ecm.core.api.NuxeoException;\n+import org.nuxeo.ecm.platform.oauth2.providers.AbstractOAuth2UserEmailProvider;\n+import org.nuxeo.ecm.platform.oauth2.providers.NuxeoOAuth2ServiceProvider;\n+import org.nuxeo.ecm.platform.oauth2.providers.OAuth2ServiceProvider;\n+import org.nuxeo.ecm.platform.oauth2.providers.OAuth2ServiceProviderRegistry;\n+import org.nuxeo.ecm.platform.oauth2.tokens.NuxeoOAuth2Token;\n+import org.nuxeo.ecm.webengine.model.WebObject;\n+import org.nuxeo.ecm.webengine.model.impl.AbstractResource;\n+import org.nuxeo.ecm.webengine.model.impl.ResourceTypeImpl;\n+import org.nuxeo.runtime.api.Framework;\n+\n+import javax.servlet.http.HttpServletRequest;\n+import javax.ws.rs.GET;\n+import javax.ws.rs.Path;\n+import javax.ws.rs.PathParam;\n+import javax.ws.rs.core.Context;\n+import javax.ws.rs.core.MediaType;\n+import javax.ws.rs.core.Response;\n+import java.io.IOException;\n+import java.io.Serializable;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+\n+/**\n+ * Endpoint to retrieve OAuth2 authentication data\n+ * @since 8.4\n+ */\n+@WebObject(type = \"oauth2\")\n+public class OAuth2Object extends AbstractResource<ResourceTypeImpl> {\n+\n+    /**\n+     * Retrieves oauth2 data for a given provider.\n+     */\n+    @GET\n+    @Path(\"provider/{providerId}\")\n+    public Response getProvider(@PathParam(\"providerId\") String providerId,\n+                                @Context HttpServletRequest request) throws IOException, RestOperationException {\n+\n+        NuxeoOAuth2ServiceProvider provider = getProvider(providerId);\n+\n+        Map<String,Object> result = new HashMap<>();\n+        result.put(\"serviceName\", provider.getServiceName());\n+        result.put(\"enabled\", provider.isEnabled());\n+        result.put(\"clientId\", provider.getClientId());\n+        result.put(\"scopes\", provider.getScopes());\n+        result.put(\"authorizationURL\", provider.getClientId() == null ? null : provider.getAuthorizationUrl(request));\n+        result.put(\"authorizationServerURL\", provider.getAuthorizationServerURL());\n+        result.put(\"tokenServerURL\", provider.getTokenServerURL());\n+\n+        String username = request.getUserPrincipal().getName();\n+        NuxeoOAuth2Token token = getToken(provider, username);\n+        boolean hasToken = (token != null);\n+        String login = hasToken ? token.getServiceLogin() : null;\n+        result.put(\"hasToken\", hasToken);","path":"nuxeo-features/rest-api/nuxeo-rest-api-server/src/main/java/org/nuxeo/ecm/restapi/server/jaxrs/OAuth2Object.java","position":84,"original_position":84,"commit_id":"99d1a6226b3ee926a184079500c7266d5f70feaf","original_commit_id":"99d1a6226b3ee926a184079500c7266d5f70feaf","user":{"login":"Gabez0r","id":13537427,"avatar_url":"https://avatars.githubusercontent.com/u/13537427?v=3","gravatar_id":"","url":"https://api.github.com/users/Gabez0r","html_url":"https://github.com/Gabez0r","followers_url":"https://api.github.com/users/Gabez0r/followers","following_url":"https://api.github.com/users/Gabez0r/following{/other_user}","gists_url":"https://api.github.com/users/Gabez0r/gists{/gist_id}","starred_url":"https://api.github.com/users/Gabez0r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gabez0r/subscriptions","organizations_url":"https://api.github.com/users/Gabez0r/orgs","repos_url":"https://api.github.com/users/Gabez0r/repos","events_url":"https://api.github.com/users/Gabez0r/events{/privacy}","received_events_url":"https://api.github.com/users/Gabez0r/received_events","type":"User","site_admin":false},"body":"Agree. Will rename it accordingly.","created_at":"2016-10-10T09:57:15Z","updated_at":"2016-10-10T09:57:15Z","html_url":"https://github.com/nuxeo/nuxeo/pull/198#discussion_r82574136","pull_request_url":"https://api.github.com/repos/nuxeo/nuxeo/pulls/198","_links":{"self":{"href":"https://api.github.com/repos/nuxeo/nuxeo/pulls/comments/82574136"},"html":{"href":"https://github.com/nuxeo/nuxeo/pull/198#discussion_r82574136"},"pull_request":{"href":"https://api.github.com/repos/nuxeo/nuxeo/pulls/198"}}},"pull_request":{"url":"https://api.github.com/repos/nuxeo/nuxeo/pulls/198","id":82864969,"html_url":"https://github.com/nuxeo/nuxeo/pull/198","diff_url":"https://github.com/nuxeo/nuxeo/pull/198.diff","patch_url":"https://github.com/nuxeo/nuxeo/pull/198.patch","issue_url":"https://api.github.com/repos/nuxeo/nuxeo/issues/198","number":198,"state":"open","locked":false,"title":"NXP-20292: add endpoint to provide OAuth2 authentication data","user":{"login":"Gabez0r","id":13537427,"avatar_url":"https://avatars.githubusercontent.com/u/13537427?v=3","gravatar_id":"","url":"https://api.github.com/users/Gabez0r","html_url":"https://github.com/Gabez0r","followers_url":"https://api.github.com/users/Gabez0r/followers","following_url":"https://api.github.com/users/Gabez0r/following{/other_user}","gists_url":"https://api.github.com/users/Gabez0r/gists{/gist_id}","starred_url":"https://api.github.com/users/Gabez0r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gabez0r/subscriptions","organizations_url":"https://api.github.com/users/Gabez0r/orgs","repos_url":"https://api.github.com/users/Gabez0r/repos","events_url":"https://api.github.com/users/Gabez0r/events{/privacy}","received_events_url":"https://api.github.com/users/Gabez0r/received_events","type":"User","site_admin":false},"body":"A proposal for exposing authentication data via REST API.","created_at":"2016-08-26T10:21:01Z","updated_at":"2016-10-10T09:57:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"735d25dcaaa99416442cf54feb8d89bd0debe0f1","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/nuxeo/nuxeo/pulls/198/commits","review_comments_url":"https://api.github.com/repos/nuxeo/nuxeo/pulls/198/comments","review_comment_url":"https://api.github.com/repos/nuxeo/nuxeo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nuxeo/nuxeo/issues/198/comments","statuses_url":"https://api.github.com/repos/nuxeo/nuxeo/statuses/99d1a6226b3ee926a184079500c7266d5f70feaf","head":{"label":"nuxeo:feature-NXP-20292-oauth2-rest","ref":"feature-NXP-20292-oauth2-rest","sha":"99d1a6226b3ee926a184079500c7266d5f70feaf","user":{"login":"nuxeo","id":460607,"avatar_url":"https://avatars.githubusercontent.com/u/460607?v=3","gravatar_id":"","url":"https://api.github.com/users/nuxeo","html_url":"https://github.com/nuxeo","followers_url":"https://api.github.com/users/nuxeo/followers","following_url":"https://api.github.com/users/nuxeo/following{/other_user}","gists_url":"https://api.github.com/users/nuxeo/gists{/gist_id}","starred_url":"https://api.github.com/users/nuxeo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nuxeo/subscriptions","organizations_url":"https://api.github.com/users/nuxeo/orgs","repos_url":"https://api.github.com/users/nuxeo/repos","events_url":"https://api.github.com/users/nuxeo/events{/privacy}","received_events_url":"https://api.github.com/users/nuxeo/received_events","type":"Organization","site_admin":false},"repo":{"id":2988101,"name":"nuxeo","full_name":"nuxeo/nuxeo","owner":{"login":"nuxeo","id":460607,"avatar_url":"https://avatars.githubusercontent.com/u/460607?v=3","gravatar_id":"","url":"https://api.github.com/users/nuxeo","html_url":"https://github.com/nuxeo","followers_url":"https://api.github.com/users/nuxeo/followers","following_url":"https://api.github.com/users/nuxeo/following{/other_user}","gists_url":"https://api.github.com/users/nuxeo/gists{/gist_id}","starred_url":"https://api.github.com/users/nuxeo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nuxeo/subscriptions","organizations_url":"https://api.github.com/users/nuxeo/orgs","repos_url":"https://api.github.com/users/nuxeo/repos","events_url":"https://api.github.com/users/nuxeo/events{/privacy}","received_events_url":"https://api.github.com/users/nuxeo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nuxeo/nuxeo","description":"Content management platform to build modern business applications","fork":false,"url":"https://api.github.com/repos/nuxeo/nuxeo","forks_url":"https://api.github.com/repos/nuxeo/nuxeo/forks","keys_url":"https://api.github.com/repos/nuxeo/nuxeo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nuxeo/nuxeo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nuxeo/nuxeo/teams","hooks_url":"https://api.github.com/repos/nuxeo/nuxeo/hooks","issue_events_url":"https://api.github.com/repos/nuxeo/nuxeo/issues/events{/number}","events_url":"https://api.github.com/repos/nuxeo/nuxeo/events","assignees_url":"https://api.github.com/repos/nuxeo/nuxeo/assignees{/user}","branches_url":"https://api.github.com/repos/nuxeo/nuxeo/branches{/branch}","tags_url":"https://api.github.com/repos/nuxeo/nuxeo/tags","blobs_url":"https://api.github.com/repos/nuxeo/nuxeo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nuxeo/nuxeo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nuxeo/nuxeo/git/refs{/sha}","trees_url":"https://api.github.com/repos/nuxeo/nuxeo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nuxeo/nuxeo/statuses/{sha}","languages_url":"https://api.github.com/repos/nuxeo/nuxeo/languages","stargazers_url":"https://api.github.com/repos/nuxeo/nuxeo/stargazers","contributors_url":"https://api.github.com/repos/nuxeo/nuxeo/contributors","subscribers_url":"https://api.github.com/repos/nuxeo/nuxeo/subscribers","subscription_url":"https://api.github.com/repos/nuxeo/nuxeo/subscription","commits_url":"https://api.github.com/repos/nuxeo/nuxeo/commits{/sha}","git_commits_url":"https://api.github.com/repos/nuxeo/nuxeo/git/commits{/sha}","comments_url":"https://api.github.com/repos/nuxeo/nuxeo/comments{/number}","issue_comment_url":"https://api.github.com/repos/nuxeo/nuxeo/issues/comments{/number}","contents_url":"https://api.github.com/repos/nuxeo/nuxeo/contents/{+path}","compare_url":"https://api.github.com/repos/nuxeo/nuxeo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nuxeo/nuxeo/merges","archive_url":"https://api.github.com/repos/nuxeo/nuxeo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nuxeo/nuxeo/downloads","issues_url":"https://api.github.com/repos/nuxeo/nuxeo/issues{/number}","pulls_url":"https://api.github.com/repos/nuxeo/nuxeo/pulls{/number}","milestones_url":"https://api.github.com/repos/nuxeo/nuxeo/milestones{/number}","notifications_url":"https://api.github.com/repos/nuxeo/nuxeo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nuxeo/nuxeo/labels{/name}","releases_url":"https://api.github.com/repos/nuxeo/nuxeo/releases{/id}","deployments_url":"https://api.github.com/repos/nuxeo/nuxeo/deployments","created_at":"2011-12-15T14:35:41Z","updated_at":"2016-09-18T08:06:29Z","pushed_at":"2016-10-10T09:43:13Z","git_url":"git://github.com/nuxeo/nuxeo.git","ssh_url":"git@github.com:nuxeo/nuxeo.git","clone_url":"https://github.com/nuxeo/nuxeo.git","svn_url":"https://github.com/nuxeo/nuxeo","homepage":"http://www.nuxeo.com","size":245908,"stargazers_count":118,"watchers_count":118,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":87,"mirror_url":null,"open_issues_count":21,"forks":87,"open_issues":21,"watchers":118,"default_branch":"master"}},"base":{"label":"nuxeo:master","ref":"master","sha":"928b0da66a55113ba4521819252dbeea85713091","user":{"login":"nuxeo","id":460607,"avatar_url":"https://avatars.githubusercontent.com/u/460607?v=3","gravatar_id":"","url":"https://api.github.com/users/nuxeo","html_url":"https://github.com/nuxeo","followers_url":"https://api.github.com/users/nuxeo/followers","following_url":"https://api.github.com/users/nuxeo/following{/other_user}","gists_url":"https://api.github.com/users/nuxeo/gists{/gist_id}","starred_url":"https://api.github.com/users/nuxeo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nuxeo/subscriptions","organizations_url":"https://api.github.com/users/nuxeo/orgs","repos_url":"https://api.github.com/users/nuxeo/repos","events_url":"https://api.github.com/users/nuxeo/events{/privacy}","received_events_url":"https://api.github.com/users/nuxeo/received_events","type":"Organization","site_admin":false},"repo":{"id":2988101,"name":"nuxeo","full_name":"nuxeo/nuxeo","owner":{"login":"nuxeo","id":460607,"avatar_url":"https://avatars.githubusercontent.com/u/460607?v=3","gravatar_id":"","url":"https://api.github.com/users/nuxeo","html_url":"https://github.com/nuxeo","followers_url":"https://api.github.com/users/nuxeo/followers","following_url":"https://api.github.com/users/nuxeo/following{/other_user}","gists_url":"https://api.github.com/users/nuxeo/gists{/gist_id}","starred_url":"https://api.github.com/users/nuxeo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nuxeo/subscriptions","organizations_url":"https://api.github.com/users/nuxeo/orgs","repos_url":"https://api.github.com/users/nuxeo/repos","events_url":"https://api.github.com/users/nuxeo/events{/privacy}","received_events_url":"https://api.github.com/users/nuxeo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nuxeo/nuxeo","description":"Content management platform to build modern business applications","fork":false,"url":"https://api.github.com/repos/nuxeo/nuxeo","forks_url":"https://api.github.com/repos/nuxeo/nuxeo/forks","keys_url":"https://api.github.com/repos/nuxeo/nuxeo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nuxeo/nuxeo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nuxeo/nuxeo/teams","hooks_url":"https://api.github.com/repos/nuxeo/nuxeo/hooks","issue_events_url":"https://api.github.com/repos/nuxeo/nuxeo/issues/events{/number}","events_url":"https://api.github.com/repos/nuxeo/nuxeo/events","assignees_url":"https://api.github.com/repos/nuxeo/nuxeo/assignees{/user}","branches_url":"https://api.github.com/repos/nuxeo/nuxeo/branches{/branch}","tags_url":"https://api.github.com/repos/nuxeo/nuxeo/tags","blobs_url":"https://api.github.com/repos/nuxeo/nuxeo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nuxeo/nuxeo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nuxeo/nuxeo/git/refs{/sha}","trees_url":"https://api.github.com/repos/nuxeo/nuxeo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nuxeo/nuxeo/statuses/{sha}","languages_url":"https://api.github.com/repos/nuxeo/nuxeo/languages","stargazers_url":"https://api.github.com/repos/nuxeo/nuxeo/stargazers","contributors_url":"https://api.github.com/repos/nuxeo/nuxeo/contributors","subscribers_url":"https://api.github.com/repos/nuxeo/nuxeo/subscribers","subscription_url":"https://api.github.com/repos/nuxeo/nuxeo/subscription","commits_url":"https://api.github.com/repos/nuxeo/nuxeo/commits{/sha}","git_commits_url":"https://api.github.com/repos/nuxeo/nuxeo/git/commits{/sha}","comments_url":"https://api.github.com/repos/nuxeo/nuxeo/comments{/number}","issue_comment_url":"https://api.github.com/repos/nuxeo/nuxeo/issues/comments{/number}","contents_url":"https://api.github.com/repos/nuxeo/nuxeo/contents/{+path}","compare_url":"https://api.github.com/repos/nuxeo/nuxeo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nuxeo/nuxeo/merges","archive_url":"https://api.github.com/repos/nuxeo/nuxeo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nuxeo/nuxeo/downloads","issues_url":"https://api.github.com/repos/nuxeo/nuxeo/issues{/number}","pulls_url":"https://api.github.com/repos/nuxeo/nuxeo/pulls{/number}","milestones_url":"https://api.github.com/repos/nuxeo/nuxeo/milestones{/number}","notifications_url":"https://api.github.com/repos/nuxeo/nuxeo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nuxeo/nuxeo/labels{/name}","releases_url":"https://api.github.com/repos/nuxeo/nuxeo/releases{/id}","deployments_url":"https://api.github.com/repos/nuxeo/nuxeo/deployments","created_at":"2011-12-15T14:35:41Z","updated_at":"2016-09-18T08:06:29Z","pushed_at":"2016-10-10T09:43:13Z","git_url":"git://github.com/nuxeo/nuxeo.git","ssh_url":"git@github.com:nuxeo/nuxeo.git","clone_url":"https://github.com/nuxeo/nuxeo.git","svn_url":"https://github.com/nuxeo/nuxeo","homepage":"http://www.nuxeo.com","size":245908,"stargazers_count":118,"watchers_count":118,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":87,"mirror_url":null,"open_issues_count":21,"forks":87,"open_issues":21,"watchers":118,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nuxeo/nuxeo/pulls/198"},"html":{"href":"https://github.com/nuxeo/nuxeo/pull/198"},"issue":{"href":"https://api.github.com/repos/nuxeo/nuxeo/issues/198"},"comments":{"href":"https://api.github.com/repos/nuxeo/nuxeo/issues/198/comments"},"review_comments":{"href":"https://api.github.com/repos/nuxeo/nuxeo/pulls/198/comments"},"review_comment":{"href":"https://api.github.com/repos/nuxeo/nuxeo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nuxeo/nuxeo/pulls/198/commits"},"statuses":{"href":"https://api.github.com/repos/nuxeo/nuxeo/statuses/99d1a6226b3ee926a184079500c7266d5f70feaf"}}}}
{"actor":{"display_login":"Gabez0r"}}