-
Notifications
You must be signed in to change notification settings - Fork 2
/
oauth2-callback.php
58 lines (50 loc) · 1.27 KB
/
oauth2-callback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require 'inc.bootstrap.php';
$info = [
'JIRA_AUTH' => false,
];
$rsp = jira_post('https://auth.atlassian.com/oauth/token', [
'grant_type' => 'authorization_code',
'client_id' => OAUTH_CLENT_ID,
'client_secret' => OAUTH_CLENT_SECRET,
'code' => $_GET['code'],
'redirect_uri' => OAUTH_REDIRECT_URL,
], $error, $info);
if ($error) {
echo '<pre>';
var_dump($error);
echo $info['response'] . "\n";
echo '<p><a href="auth.php">Retry</a></p>';
exit;
}
$auth = 'Bearer ' . $rsp->access_token;
$info = [
'JIRA_AUTH' => $auth,
'unauth_ok' => true,
];
$rsp = jira_get('https://api.atlassian.com/oauth/token/accessible-resources', [], $error, $info);
if ($error) {
echo '<pre>';
var_dump($error);
print_r($info);
echo '<p><a href="auth.php">Retry</a></p>';
exit;
}
$server = $rsp[0]->url;
$url = sprintf('https://api.atlassian.com/ex/jira/%s', $rsp[0]->id);
$info = [
'JIRA_AUTH' => $auth,
'unauth_ok' => true,
];
$rsp = jira_get("$url/rest/api/3/myself", [], $error, $info);
// $rsp = jira_get("$url/rest/auth/1/session", [], $error, $info);
if ($error) {
echo '<pre>';
var_dump($error);
print_r($info);
echo '<p><a href="auth.php">Retry</a></p>';
exit;
}
$username = $rsp->emailAddress;
do_login($url, $info['JIRA_AUTH'], $username, $server);
return do_redirect('index');