Skip to content
This repository was archived by the owner on Nov 26, 2023. It is now read-only.

Commit eeeb261

Browse files
committed
Merge branch 'hotfix/1.2.3'
2 parents 1a66456 + 6d848ba commit eeeb261

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [1.2.3] - 2018-08-15
9+
10+
### Fixed
11+
- Fixed the "Unauthorized" bug on requests with spaced query parameter values (https://github.com/brezzhnev/atlassian-connect-core/issues/9).
12+
813
## [1.2.2] - 2018-01-13
914

1015
### Added
@@ -51,7 +56,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5156
### Fixed
5257
- Package keywords at composer.json
5358

54-
[Unreleased]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.2.2...HEAD
59+
[Unreleased]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.2.3...HEAD
60+
[1.2.3]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.2.2...v1.2.3
5561
[1.2.2]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.2.1...v1.2.2
5662
[1.2.1]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.2.0...v1.2.1
5763
[1.2.0]: https://github.com/brezzhnev/atlassian-connect-core/compare/v1.1.0...v1.2.0

src/Helpers/JWTHelper.php

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static function create(string $url, string $method, string $issuer, strin
5757
* Create Query String Hash
5858
*
5959
* More details:
60-
* https://developer.atlassian.com/static/connect/docs/latest/concepts/understanding-jwt.html#creating-token
60+
* https://docs.atlassian.com/DAC/bitbucket/concepts/qsh.html
6161
*
6262
* @param string $url URL of the request
6363
* @param string $method HTTP method
@@ -67,40 +67,37 @@ public static function create(string $url, string $method, string $issuer, strin
6767
public static function qsh($url, $method)
6868
{
6969
$method = strtoupper($method);
70-
$parts = parse_url($url);
7170

72-
// Remove "/wiki" part from the path for the Confluence
73-
// Really, I didn't find this part in the docs, but it works
74-
$path = str_replace('/wiki', '', $parts['path']);
71+
$parts = parse_url($url);
72+
$path = $parts['path'];
7573

76-
$canonicalQuery = '';
74+
// The list of prefixes which must be removed from the path
75+
$prefixes = ['/wiki'];
7776

78-
if (!empty($parts['query'])) {
79-
$query = $parts['query'];
80-
$queryParts = explode('&', $query);
81-
$queryArray = [];
77+
foreach ($prefixes as $prefix) {
78+
$path = preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $path);
79+
}
8280

83-
foreach ($queryParts as $queryPart) {
84-
$pieces = explode('=', $queryPart);
85-
$key = array_shift($pieces);
86-
$key = rawurlencode($key);
87-
$value = substr($queryPart, strlen($key) + 1);
88-
$value = rawurlencode($value);
89-
$queryArray[$key][] = $value;
90-
}
81+
// Parse a query into the map of parameters
82+
parse_str($parts['query'], $params);
9183

92-
ksort($queryArray);
84+
// Parameters should be sorted alphabetically
85+
ksort($params);
9386

94-
foreach ($queryArray as $key => $pieceOfQuery) {
95-
$pieceOfQuery = implode(',', $pieceOfQuery);
96-
$canonicalQuery .= $key . '=' . $pieceOfQuery . '&';
97-
}
87+
$canonicalQuery = http_build_query(
88+
$params,
89+
null,
90+
'&',
91+
PHP_QUERY_RFC3986
92+
);
9893

99-
$canonicalQuery = rtrim($canonicalQuery, '&');
100-
}
94+
$parts = [
95+
strtoupper($method),
96+
$path,
97+
$canonicalQuery
98+
];
10199

102-
$qshString = implode('&', [$method, $path, $canonicalQuery]);
103-
$qsh = hash('sha256', $qshString);
100+
$qsh = hash('sha256', implode('&', $parts));
104101

105102
return $qsh;
106103
}

0 commit comments

Comments
 (0)