-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenStreetmap2.php
67 lines (56 loc) · 2.24 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
<?php
/**
* Class OpenStreetmap2
*
* @created 05.03.2024
* @author smiley <smiley@chillerlan.net>
* @copyright 2024 smiley
* @license MIT
*
* @noinspection PhpUnused
*/
declare(strict_types=1);
namespace chillerlan\OAuth\Providers;
use chillerlan\OAuth\Core\{AuthenticatedUser, CSRFToken, OAuth2Provider, UserInfo};
/**
* OpenStreetmap OAuth2
*
* @link https://wiki.openstreetmap.org/wiki/API
* @link https://wiki.openstreetmap.org/wiki/OAuth
* @link https://www.openstreetmap.org/.well-known/oauth-authorization-server
*/
class OpenStreetmap2 extends OAuth2Provider implements CSRFToken, UserInfo{
public const IDENTIFIER = 'OPENSTREETMAP2';
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';
public const DEFAULT_SCOPES = [
self::SCOPE_READ_GPX,
self::SCOPE_READ_PREFS,
];
protected string $authorizationURL = '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';
/** @codeCoverageIgnore */
public function me():AuthenticatedUser{
$json = $this->getMeResponseData('/api/0.6/user/details.json');
$userdata = [
'data' => $json,
'avatar' => $json['user']['img']['href'],
'displayName' => $json['user']['display_name'],
'id' => $json['user']['id'],
];
return new AuthenticatedUser($userdata);
}
}