friendship ended with social-app. php is my new best friend
1<?php
2/**
3 * Class OpenStreetmap2
4 *
5 * @created 05.03.2024
6 * @author smiley <smiley@chillerlan.net>
7 * @copyright 2024 smiley
8 * @license MIT
9 *
10 * @noinspection PhpUnused
11 */
12declare(strict_types=1);
13
14namespace chillerlan\OAuth\Providers;
15
16use chillerlan\OAuth\Core\{AuthenticatedUser, CSRFToken, OAuth2Provider, UserInfo};
17
18/**
19 * OpenStreetmap OAuth2
20 *
21 * @link https://wiki.openstreetmap.org/wiki/API
22 * @link https://wiki.openstreetmap.org/wiki/OAuth
23 * @link https://www.openstreetmap.org/.well-known/oauth-authorization-server
24 */
25class OpenStreetmap2 extends OAuth2Provider implements CSRFToken, UserInfo{
26
27 public const IDENTIFIER = 'OPENSTREETMAP2';
28
29 public const SCOPE_READ_PREFS = 'read_prefs';
30 public const SCOPE_WRITE_PREFS = 'write_prefs';
31 public const SCOPE_WRITE_DIARY = 'write_diary';
32 public const SCOPE_WRITE_API = 'write_api';
33 public const SCOPE_READ_GPX = 'read_gpx';
34 public const SCOPE_WRITE_GPX = 'write_gpx';
35 public const SCOPE_WRITE_NOTES = 'write_notes';
36# public const SCOPE_READ_EMAIL = 'read_email';
37# public const SCOPE_SKIP_AUTH = 'skip_authorization';
38 public const SCOPE_WRITE_REDACTIONS = 'write_redactions';
39 public const SCOPE_OPENID = 'openid';
40
41 public const DEFAULT_SCOPES = [
42 self::SCOPE_READ_GPX,
43 self::SCOPE_READ_PREFS,
44 ];
45
46 protected string $authorizationURL = 'https://www.openstreetmap.org/oauth2/authorize';
47 protected string $accessTokenURL = 'https://www.openstreetmap.org/oauth2/token';
48# protected string $revokeURL = 'https://www.openstreetmap.org/oauth2/revoke'; // not implemented yet?
49 protected string $apiURL = 'https://api.openstreetmap.org';
50 protected string|null $apiDocs = 'https://wiki.openstreetmap.org/wiki/API';
51 protected string|null $applicationURL = 'https://www.openstreetmap.org/oauth2/applications';
52
53 /** @codeCoverageIgnore */
54 public function me():AuthenticatedUser{
55 $json = $this->getMeResponseData('/api/0.6/user/details.json');
56
57 $userdata = [
58 'data' => $json,
59 'avatar' => $json['user']['img']['href'],
60 'displayName' => $json['user']['display_name'],
61 'id' => $json['user']['id'],
62 ];
63
64 return new AuthenticatedUser($userdata);
65 }
66
67}