{"id":21732159,"url":"https://github.com/jbelien/oauth2-openstreetmap","last_synced_at":"2025-04-13T00:36:17.347Z","repository":{"id":37589549,"uuid":"396311960","full_name":"jbelien/oauth2-openstreetmap","owner":"jbelien","description":"OpenStreetMap OAuth 2.0 support for the PHP League's OAuth 2.0 Client ","archived":false,"fork":false,"pushed_at":"2024-05-14T17:51:46.000Z","size":118,"stargazers_count":3,"open_issues_count":5,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-13T00:36:13.132Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jbelien.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-15T10:26:49.000Z","updated_at":"2024-05-14T05:35:02.000Z","dependencies_parsed_at":"2024-11-26T04:48:20.939Z","dependency_job_id":null,"html_url":"https://github.com/jbelien/oauth2-openstreetmap","commit_stats":{"total_commits":32,"total_committers":4,"mean_commits":8.0,"dds":0.28125,"last_synced_commit":"5451832ffa51e8ec581a0b4d6a553d85f702a3a3"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbelien%2Foauth2-openstreetmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbelien%2Foauth2-openstreetmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbelien%2Foauth2-openstreetmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbelien%2Foauth2-openstreetmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbelien","download_url":"https://codeload.github.com/jbelien/oauth2-openstreetmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650417,"owners_count":21139671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-26T04:29:02.009Z","updated_at":"2025-04-13T00:36:17.327Z","avatar_url":"https://github.com/jbelien.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenStreetMap Provider for OAuth 2.0 Client\n\nThis package provides OpenStreetMap OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).\n\n## Installation\n\n```cmd\ncomposer require jbelien/oauth2-OpenStreetMap\n```\n\n## Usage\n\n```php\n$OpenStreetMapProvider = new \\JBelien\\OAuth2\\Client\\Provider\\OpenStreetMap([\n    'clientId'     =\u003e 'yourId',          // The client ID assigned to you by OpenStreetMap.org\n    'clientSecret' =\u003e 'yourSecret',      // The client password assigned to you by OpenStreetMap.org\n    'redirectUri'  =\u003e 'yourRedirectUri', // The return URL you specified for your app on OpenStreetMap.org\n    'dev'          =\u003e false              // Whether to use the OpenStreetMap test environment at https://master.apis.dev.openstreetmap.org/\n]);\n\n// Get authorization code\nif (!isset($_GET['code'])) {\n    // Options are optional, defaults to 'read_prefs' only\n    $options = ['scope' =\u003e 'read_prefs read_gpx'];\n    // Get authorization URL\n    $authorizationUrl = $OpenStreetMapProvider-\u003egetAuthorizationUrl($options);\n\n    // Get state and store it to the session\n    $_SESSION['oauth2state'] = $OpenStreetMapProvider-\u003egetState();\n\n    // Redirect user to authorization URL\n    header('Location: ' . $authorizationUrl);\n    exit;\n// Check for errors\n} elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) \u0026\u0026 $_GET['state'] !== $_SESSION['oauth2state'])) {\n    if (isset($_SESSION['oauth2state'])) {\n        unset($_SESSION['oauth2state']);\n    }\n    exit('Invalid state');\n} else {\n    // Get access token\n    try {\n        $accessToken = $OpenStreetMapProvider-\u003egetAccessToken(\n            'authorization_code',\n            [\n                'code' =\u003e $_GET['code']\n            ]\n        );\n    } catch (\\League\\OAuth2\\Client\\Provider\\Exception\\IdentityProviderException $e) {\n        exit($e-\u003egetMessage());\n    }\n\n    // Get resource owner\n    try {\n        $resourceOwner = $OpenStreetMapProvider-\u003egetResourceOwner($accessToken);\n    } catch (\\League\\OAuth2\\Client\\Provider\\Exception\\IdentityProviderException $e) {\n        exit($e-\u003egetMessage());\n    }\n        \n    // Now you can store the results to session etc.\n    $_SESSION['accessToken'] = $accessToken;\n    $_SESSION['resourceOwner'] = $resourceOwner;\n    \n    var_dump(\n        $resourceOwner-\u003egetId(),\n        $resourceOwner-\u003egetDisplayName(),\n        $resourceOwner-\u003egetAccountCreated(),\n        $resourceOwner-\u003egetImage(),\n        $resourceOwner-\u003egetChangesetsCount(),\n        $resourceOwner-\u003egetLanguages(),\n        $resourceOwner-\u003etoArray()\n    );\n}\n```\n\nFor more information see the PHP League's general usage examples.\n\n## Testing\n\n``` bash\n./vendor/bin/phpunit\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/jbelien/oauth2-openstreetmap/blob/master/LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbelien%2Foauth2-openstreetmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbelien%2Foauth2-openstreetmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbelien%2Foauth2-openstreetmap/lists"}