Homec4science

Implement most of a JIRA adapter

Authored by epriestley <git@epriestley.com> on Aug 8 2013, 22:33.

Description

Implement most of a JIRA adapter

Summary:
Ref T3687. Builds on previous OAuth1 / Twitter work to get JIRA and its onerous RSA-SHA1 signing method working.

Ultimately, here's the good news -- the sessions are 5 years long:

array(5) {
  'oauth_token' =>
  string(32) "M1zOlAzuqW0CaUxoha0sACz5fM56OHTT"
  'oauth_token_secret' =>
  string(32) "qZXHqrGLWCarQBAbk8YXboBt5kW8AYUS"
  'oauth_expires_in' =>
  string(9) "157680000"
  'oauth_session_handle' =>
  string(32) "UE9qSvxIqn05P27R3Ac5Bt2zykKRQd59"
  'oauth_authorization_expires_in' =>
  string(9) "160272000"
}

Test Plan:
Ran this script and got a session out of JIRA:

<?php

require_once dirname(__FILE__).'/__init_script__.php';

/*

This will generate a new keypair.

list($public, $private) = PhutilAuthAdapterOAuthJIRA::newJIRAKeypair();
print_r(
  array(
    'public' => $public,
    'private' => $private,
  ));

*/

$public_key = <<<EOKEY
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAz/cLggl8VtHsZAtQudfz
fN14/xZgtUxA/J10jVwaz30etSiTY1QmeUbL09XKM7NyIL432+AbJkLEJ/EF6NIh
XkqrtrDvi+48zcSl0zwHthGjESLve9o0i9m1EjEaztnv8EdaNuXkUtYfEMUm9KEk
iocXTdyLszdtrGOPY1h4qQUrgxO0JY0bBoRa6PqiGe7M/3yvstbW0DGNGvNvLaq7
k54tPCDKWGKphoEQ6wxd5Hk30LEKn0dqZ5i11ZYal4bfj7UkvjiA5bgAAZmyQ1IV
CqzMQsPLwAlw/8xyu9EnCE49odmPKn/cbvY5vhoRwDbHDsOuwEPvoFCV9hoXvWhT
GfWcxDihkgBVDzqHZYgCctTjr+4eZvryBOemPK4FaiEHQ4ZQswX6KT5tW7HcjaQ3
kGz2pgOstLBGu9EN6t4kmFDLFOzWEYM5CfSuaE54pnfNJNXuTER/a1S8N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t7g
7sLZCeNA2yl8jLttCkHacramIZ8jDvauS3+2UKL/r/hzpqEwiUkCcI9qLNwDQFxs
nNXE0ISoMvcPWNJcghoH9zx9EQ5rpLPSImWlc9GjjKkJJ8hjwdp4s0janJUojLRX
6tdI84ziz6fr/HmFYEDkgttL0EFnSDBG+atth14eLjASloLrlobEcEhwmuvJJ3rS
xIGlOymzmWzoj2NxVK8H9GLcOG6ftULAMTZgUwayjTLxCLrErlRUVkM7Pg==
-----END RSA PRIVATE KEY-----
EOKEY;

$adapter = id(new PhutilAuthAdapterOAuthJIRA())
  ->setJIRABaseURI('http://local.aphront.com:8090/')
  ->setCallbackURI('http://local.aphront.com:8080/auth/login/jira:derp/')
  ->setConsumerKey('quackquack')
  ->setPrivateKey(new PhutilOpaqueEnvelope($private_key));

$clean_adapter = clone $adapter;

echo "Open your browser and visit this URL:\n\n";
echo "    ".$adapter->getClientRedirectURI()."\n";
$response = phutil_console_prompt("Where does that redirect you?");

$response_uri = new PhutilURI($response);
$params = $response_uri->getQueryParams();

$clean_adapter->setToken(idx($params, 'oauth_token'));
$clean_adapter->setVerifier(idx($params, 'oauth_verifier'));

var_dump($clean_adapter->getAccountID());

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3687

Differential Revision: https://secure.phabricator.com/D6704

Details

Committed
epriestley <git@epriestley.com>Aug 8 2013, 22:33
Pushed
aubortMar 17 2017, 12:03
Parents
rPHU3e2755e57c0a: Add a Twitter OAuth1 adapter
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHUc3ff756d5606: Implement most of a JIRA adapter (authored by epriestley <git@epriestley.com>).Aug 8 2013, 22:33