This repository was archived by the owner on Mar 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenStreetmap2.php
71 lines (59 loc) · 2.32 KB
/
OpenStreetmap2.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
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Class OpenStreetmap2
*
* @created 05.03.2024
* @author smiley <smiley@chillerlan.net>
* @copyright 2024 smiley
* @license MIT
*/
namespace chillerlan\OAuth\Providers;
use chillerlan\HTTP\Utils\MessageUtil;
use chillerlan\OAuth\Core\{CSRFToken, OAuth2Provider, ProviderException};
use Psr\Http\Message\ResponseInterface;
use function sprintf, strip_tags;
/**
* @see https://wiki.openstreetmap.org/wiki/API
* @see https://wiki.openstreetmap.org/wiki/OAuth
* @see https://www.openstreetmap.org/.well-known/oauth-authorization-server
*
* @see https://github.com/chillerlan/php-oauth-providers/issues/2
*/
class OpenStreetmap2 extends OAuth2Provider implements CSRFToken{
public const SCOPE_READ_PREFS = 'read_prefs';
public const SCOPE_WRITE_PREFS = 'write_prefs';
public const SCOPE_WRITE_DIARY = 'write_diary';
public const SCOPE_WRITE_API = 'write_api';
public const SCOPE_READ_GPX = 'read_gpx';
public const SCOPE_WRITE_GPX = 'write_gpx';
public const SCOPE_WRITE_NOTES = 'write_notes';
# public const SCOPE_READ_EMAIL = 'read_email';
# public const SCOPE_SKIP_AUTH = 'skip_authorization';
public const SCOPE_WRITE_REDACTIONS = 'write_redactions';
public const SCOPE_OPENID = 'openid';
protected array $defaultScopes = [
self::SCOPE_READ_GPX,
self::SCOPE_READ_PREFS,
];
protected string $authURL = 'https://www.openstreetmap.org/oauth2/authorize';
protected string $accessTokenURL = 'https://www.openstreetmap.org/oauth2/token';
# protected string $revokeURL = 'https://www.openstreetmap.org/oauth2/revoke'; // not implemented yet?
protected string $apiURL = 'https://api.openstreetmap.org';
protected string|null $apiDocs = 'https://wiki.openstreetmap.org/wiki/API';
protected string|null $applicationURL = 'https://www.openstreetmap.org/oauth2/applications';
/**
* @inheritDoc
*/
public function me():ResponseInterface{
$response = $this->request('/api/0.6/user/details.json');
$status = $response->getStatusCode();
if($status === 200){
return $response;
}
$body = MessageUtil::getContents($response);
if(!empty($body)){
throw new ProviderException(strip_tags($body));
}
throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
}
}