{"id":23489929,"url":"https://github.com/tulipretail/oauth2-hydra","last_synced_at":"2025-04-15T04:30:47.973Z","repository":{"id":57073579,"uuid":"118968986","full_name":"tulipretail/oauth2-hydra","owner":"tulipretail","description":"Hydra Provider for the PHP League OAuth 2.0 Client","archived":false,"fork":false,"pushed_at":"2018-11-28T22:17:47.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T15:51:57.924Z","etag":null,"topics":["composer","hydra","oauth2","oidc","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tulipretail.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-25T21:19:52.000Z","updated_at":"2018-11-28T22:16:56.000Z","dependencies_parsed_at":"2022-08-24T14:54:41.825Z","dependency_job_id":null,"html_url":"https://github.com/tulipretail/oauth2-hydra","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tulipretail%2Foauth2-hydra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tulipretail%2Foauth2-hydra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tulipretail%2Foauth2-hydra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tulipretail%2Foauth2-hydra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tulipretail","download_url":"https://codeload.github.com/tulipretail/oauth2-hydra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249006317,"owners_count":21197249,"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":["composer","hydra","oauth2","oidc","php"],"created_at":"2024-12-25T00:12:38.995Z","updated_at":"2025-04-15T04:30:47.946Z","avatar_url":"https://github.com/tulipretail.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Hydra PHP Oauth2 Client\n=======================\n\nThis package provides [Hydra](https://github.com/ory/hydra) OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).\n\n## Installation\n\nTo install, use composer:\n\n```\ncomposer require tulip/oauth2-hydra\n```\n\n## Usage\n\nUsage is the same as The League's OAuth client, using `\\Hydra\\OAuth2\\Provider\\OAuth2` as the provider.\n\n### With the Hydra SDK\n\nYou can use this library to acquire an access token for use with the Hydra SDK.\n\nHere we get one with the 'hydra.clients' scope:\n\n```\n    $provider = new \\Hydra\\OAuth2\\Provider\\OAuth2([\n        'clientId' =\u003e 'admin',\n        'clientSecret' =\u003e 'demo-password',\n        'domain' =\u003e 'https://your-hydra-domain',\n    ]);\n\n    try {\n        // Get an access token using the client credentials grant.\n        // Note that you must separate multiple scopes with a plus (+)\n        $accessToken = $provider-\u003egetAccessToken(\n            'client_credentials', ['scope' =\u003e 'hydra.clients']\n        );\n    } catch (\\Hydra\\Oauth2\\Provider\\Exception\\ConnectionException $e) {\n        die(\"Connection to Hydra failed: \".$e-\u003egetMessage());\n    } catch (\\Hydra\\Oauth2\\Provider\\Exception\\IdentityProviderException $e) {\n        die(\"Failed to get an access token: \".$e-\u003egetMessage());\n    }\n\n    // You may now pass $accessToken to the hydra SDK to manage clients\n```\n\n### As an OIDC Client\n\nYou can also use this library if you are a Relying Party.\n\nHere we send users to Hydra to authenticate so that we can complete the authorization code flow:\n\n```\n    $provider = new \\Hydra\\OAuth2\\Provider\\OAuth2([\n        'clientId' =\u003e 'admin',\n        'clientSecret' =\u003e 'demo-password',\n        'domain' =\u003e 'https://your-hydra-domain',\n        // Be sure this is a redirect URI you registered with Hydra for your client!\n        'redirectUri' =\u003e 'http://your-domain.com/bobsflowers',\n    ]);\n\n    if (!isset($_GET['code'])) {\n\n        // If we don't have an authorization code then get one\n        $authUrl = $provider-\u003egetAuthorizationUrl(['scope' =\u003e ['openid']]);\n        $_SESSION['oauth2state'] = $provider-\u003egetState();\n        header('Location: '.$authUrl);\n        die();\n\n    // Check given state against previously stored one to mitigate CSRF attack\n    } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {\n\n        unset($_SESSION['oauth2state']);\n        die('Invalid state');\n\n    } else {\n\n        // Try to get an access token (using the authorization code grant)\n        $token = $provider-\u003egetAccessToken('authorization_code', [\n            'code' =\u003e $_GET['code']\n        ]);\n\n        // Optional: Now you have a token you can look up a users profile data\n        try {\n\n            // We got an access token, let's now get the user's details\n            $user = $provider-\u003egetResourceOwner($token);\n\n            // $user contains public claims from the id token\n            printf('User info: ', json_encode($user));\n\n        } catch (\\Hydra\\Oauth2\\Provider\\Exception\\IdentityProviderException $e) {\n            die('Unable to fetch user details: '.$e-\u003egetMessage());\n        }\n\n        // Use this to interact with an API on the users behalf\n        echo $token-\u003egetToken();\n    }\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftulipretail%2Foauth2-hydra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftulipretail%2Foauth2-hydra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftulipretail%2Foauth2-hydra/lists"}