{"action":"created","issue":{"url":"https://api.github.com/repos/imapsync/imapsync/issues/25","labels_url":"https://api.github.com/repos/imapsync/imapsync/issues/25/labels{/name}","comments_url":"https://api.github.com/repos/imapsync/imapsync/issues/25/comments","events_url":"https://api.github.com/repos/imapsync/imapsync/issues/25/events","html_url":"https://github.com/imapsync/imapsync/pull/25","id":58001706,"number":25,"title":"XOAUTH2 Support","user":{"login":"Secretions","id":1669783,"avatar_url":"https://avatars.githubusercontent.com/u/1669783?v=3","gravatar_id":"","url":"https://api.github.com/users/Secretions","html_url":"https://github.com/Secretions","followers_url":"https://api.github.com/users/Secretions/followers","following_url":"https://api.github.com/users/Secretions/following{/other_user}","gists_url":"https://api.github.com/users/Secretions/gists{/gist_id}","starred_url":"https://api.github.com/users/Secretions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Secretions/subscriptions","organizations_url":"https://api.github.com/users/Secretions/orgs","repos_url":"https://api.github.com/users/Secretions/repos","events_url":"https://api.github.com/users/Secretions/events{/privacy}","received_events_url":"https://api.github.com/users/Secretions/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-17T23:47:10Z","updated_at":"2015-08-17T15:10:37Z","closed_at":"2015-05-28T17:06:26Z","pull_request":{"url":"https://api.github.com/repos/imapsync/imapsync/pulls/25","html_url":"https://github.com/imapsync/imapsync/pull/25","diff_url":"https://github.com/imapsync/imapsync/pull/25.diff","patch_url":"https://github.com/imapsync/imapsync/pull/25.patch"},"body":"Here is a pull request that would add XOAUTH2 support. Google's OAUTH1 support is coming to an end soon (see: https://developers.google.com/accounts/docs/OAuth#shutdown-timetable), so XOAUTH2 will now be the only way to move accounts to/from Gmail in bulk.\r\n\r\nOAUTH2 (with Google) requires creating a service account and using an encrypted keyfile. This oauth2 support  uses special input to the --passwordX argument to communicate those variables. This could be used as-is, or used as the basis for support with a different interface (custom --arguments for the keyfile, etc., when using XOAUTH2--looking at the code, the way I did it seemed much simpler, but perhaps it's too obtuse from a user's perspective?).\r\n\r\nThis introduces a requirement for JSON::WebToken.\r\n\r\nHere are the instructions from the commit:\r\n\r\nMakes --authmechX accept \"XOAUTH2\", which then uses the password for parameters.\r\n\r\n--passwordX needs to be in the following format:\r\n\"<service account>;<keyfile location>;<keyfile password>\"\r\n\r\n<service account> is the name of the Google Developer API service account.\r\n\r\n<keyfile location> is the location of the keyfile associated with it.\r\n\r\n<keyfile password> is the password to access the keyfile. Entering this\r\npassword is optional--it will assume \"notasecret\" if not provided, which\r\nis the default password Google uses with the keyfiles.\r\n\r\nExample arguments for using XOAUTH might look like this:\r\n\r\n--authmech1 xoauth2 --password1 '123456789012-abcd0abcde0ab1abc2345ab6abcdefgh@developer.gserviceaccount.com;some_keyfile.p12'\r\n\r\nThis assumes \"some_keyfile\" is in the current directory, and uses the default\r\n\"notasecret\" password."},"comment":{"url":"https://api.github.com/repos/imapsync/imapsync/issues/comments/131856905","html_url":"https://github.com/imapsync/imapsync/pull/25#issuecomment-131856905","issue_url":"https://api.github.com/repos/imapsync/imapsync/issues/25","id":131856905,"user":{"login":"sandromello","id":586235,"avatar_url":"https://avatars.githubusercontent.com/u/586235?v=3","gravatar_id":"","url":"https://api.github.com/users/sandromello","html_url":"https://github.com/sandromello","followers_url":"https://api.github.com/users/sandromello/followers","following_url":"https://api.github.com/users/sandromello/following{/other_user}","gists_url":"https://api.github.com/users/sandromello/gists{/gist_id}","starred_url":"https://api.github.com/users/sandromello/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sandromello/subscriptions","organizations_url":"https://api.github.com/users/sandromello/orgs","repos_url":"https://api.github.com/users/sandromello/repos","events_url":"https://api.github.com/users/sandromello/events{/privacy}","received_events_url":"https://api.github.com/users/sandromello/received_events","type":"User","site_admin":false},"created_at":"2015-08-17T15:10:37Z","updated_at":"2015-08-17T15:10:37Z","body":"I've tried to use this function and some errors occurred due to the way the packages is imported:\r\nUndefined subroutine &main::decode_json called at /usr/bin/imapsync line 2455.\r\n\r\nThis happens also with encode_entities\r\n\r\nI've fixed calling directly from the package:\r\n\r\n```\r\n(...)\r\n # Post oauth2 request\r\n my $ua = LWP::UserAgent->new();\r\n my $response = $ua->post('https://www.googleapis.com/oauth2/v3/token',\r\n { grant_type => HTML::Entities::encode_entities('urn:ietf:params:oauth:grant-type:jwt-bearer'),\r\n assertion => $jwt } );\r\n\r\n unless($response->is_success()) {\r\n die($response->code, \"\\n\", $response->content, \"\\n\");\r\n }\r\n\r\n # access_token in response is what we need\r\n my $data = JSON::decode_json($response->content);\r\n(...)\r\n```"}}