{"id":20347982,"url":"https://github.com/omines/oauth2-gitlab","last_synced_at":"2025-08-20T14:32:39.201Z","repository":{"id":51807996,"uuid":"58928652","full_name":"omines/oauth2-gitlab","owner":"omines","description":"GitLab Provider for the OAuth 2.0 Client","archived":false,"fork":false,"pushed_at":"2024-03-11T11:33:23.000Z","size":114,"stargazers_count":35,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-09-18T18:49:03.334Z","etag":null,"topics":["gitlab","gitlab-provider","oauth2","oauth2-client","php"],"latest_commit_sha":null,"homepage":"","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/omines.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2016-05-16T11:51:29.000Z","updated_at":"2024-06-20T03:36:03.000Z","dependencies_parsed_at":"2022-08-23T17:41:00.571Z","dependency_job_id":"e3a46175-1450-4628-a1f8-e01dc232e731","html_url":"https://github.com/omines/oauth2-gitlab","commit_stats":{"total_commits":83,"total_committers":8,"mean_commits":10.375,"dds":"0.28915662650602414","last_synced_commit":"bd2714c54870e98b8603a3959d6d4a102a2d6889"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omines%2Foauth2-gitlab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omines%2Foauth2-gitlab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omines%2Foauth2-gitlab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omines%2Foauth2-gitlab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omines","download_url":"https://codeload.github.com/omines/oauth2-gitlab/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230431103,"owners_count":18224655,"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":["gitlab","gitlab-provider","oauth2","oauth2-client","php"],"created_at":"2024-11-14T22:18:46.843Z","updated_at":"2024-12-19T12:11:45.745Z","avatar_url":"https://github.com/omines.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GitLab Provider for OAuth 2.0 Client\n[![Latest Version](https://img.shields.io/github/release/omines/oauth2-gitlab.svg?style=flat-square)](https://github.com/omines/oauth2-gitlab/releases)\n[![Total Downloads](https://img.shields.io/packagist/dt/omines/oauth2-gitlab.svg?style=flat-square)](https://packagist.org/packages/omines/oauth2-gitlab)\n[![test suite](https://github.com/omines/oauth2-gitlab/actions/workflows/ci.yaml/badge.svg)](https://github.com/omines/oauth2-gitlab/actions/workflows/ci.yaml)\n[![codecov](https://codecov.io/gh/omines/oauth2-gitlab/graph/badge.svg?token=sAqu9IFaYQ)](https://codecov.io/gh/omines/oauth2-gitlab)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fomines%2Foauth2-gitlab%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/omines/oauth2-gitlab/master)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n\nThis package provides GitLab 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 omines/oauth2-gitlab\n```\n\n## Usage\n\nUsage is similar to the basic OAuth client, using `\\Omines\\OAuth2\\Client\\Provider\\Gitlab` as the provider.\n\n### Authorization Code Flow\n\n```php\n$provider = new \\Omines\\OAuth2\\Client\\Provider\\Gitlab([\n    'clientId'          =\u003e '{gitlab-client-id}',\n    'clientSecret'      =\u003e '{gitlab-client-secret}',\n    'redirectUri'       =\u003e 'https://example.com/callback-url',\n    'domain'            =\u003e 'https://my.gitlab.example',      // Optional base URL for self-hosted\n]);\n\nif (!isset($_GET['code'])) {\n\n    // If we don't have an authorization code then get one\n    $authUrl = $provider-\u003egetAuthorizationUrl();\n    $_SESSION['oauth2state'] = $provider-\u003egetState();\n    header('Location: '.$authUrl);\n    exit;\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    exit('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        // Use these details to create a new profile\n        printf('Hello %s!', $user-\u003egetName());\n\n    } catch (Exception $e) {\n\n        // Failed to get user details\n        exit('Oh dear...');\n    }\n\n    // Use this to interact with an API on the users behalf\n    echo $token-\u003egetToken();\n}\n```\n\n### Managing Scopes\n\nWhen creating your GitLab authorization URL, you can specify the state and scopes your application may authorize.\n\n```php\n$options = [\n    'state' =\u003e 'OPTIONAL_CUSTOM_CONFIGURED_STATE',\n    'scope' =\u003e ['read_user','openid'] // array or string\n];\n\n$authorizationUrl = $provider-\u003egetAuthorizationUrl($options);\n```\nIf neither are defined, the provider will utilize internal defaults ```'api'```.\n\n\n### Performing API calls\n\nInstall [`m4tthumphrey/php-gitlab-api`](https://packagist.org/packages/m4tthumphrey/php-gitlab-api) to interact with the\nGitlab API after authentication. Either connect manually:\n\n```php\n$client = new \\Gitlab\\Client();\n$client-\u003esetUrl('https://my.gitlab.url/api/v4/');\n$client-\u003eauthenticate($token-\u003egetToken(), \\Gitlab\\Client::AUTH_OAUTH_TOKEN);\n```\nOr call the `getApiClient` method on `GitlabResourceOwner` which does the same implicitly.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/omines/oauth2-gitlab/blob/master/CONTRIBUTING.md) for details.\n\n## Credits\n\nThis code is a modified fork from the [official Github provider](https://github.com/thephpleague/oauth2-github) adapted\nfor Gitlab use, so many credits go to [Steven Maguire](https://github.com/stevenmaguire).\n\n## Legal\n\nThis software was developed for internal use at [Omines Full Service Internetbureau](https://www.omines.nl/)\nin Eindhoven, the Netherlands. It is shared with the general public under the permissive MIT license, without\nany guarantee of fitness for any particular purpose. Refer to the included `LICENSE` file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomines%2Foauth2-gitlab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomines%2Foauth2-gitlab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomines%2Foauth2-gitlab/lists"}