{"id":20906624,"url":"https://github.com/authress/authress-sdk.php","last_synced_at":"2025-07-07T12:03:18.539Z","repository":{"id":56963158,"uuid":"337471575","full_name":"Authress/authress-sdk.php","owner":"Authress","description":"The Authress SDK for PHP provides authorization as a service with fully compatible REST apis.","archived":false,"fork":false,"pushed_at":"2024-10-29T12:03:58.000Z","size":775,"stargazers_count":3,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"release/0.3","last_synced_at":"2024-10-29T16:27:08.794Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Authress.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-02-09T16:47:43.000Z","updated_at":"2024-10-29T12:03:31.000Z","dependencies_parsed_at":"2024-02-21T11:52:40.382Z","dependency_job_id":null,"html_url":"https://github.com/Authress/authress-sdk.php","commit_stats":{"total_commits":38,"total_committers":5,"mean_commits":7.6,"dds":"0.39473684210526316","last_synced_commit":"c93bbd732036503c9cec92a51c618d5f04ce1671"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authress%2Fauthress-sdk.php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authress%2Fauthress-sdk.php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authress%2Fauthress-sdk.php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authress%2Fauthress-sdk.php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Authress","download_url":"https://codeload.github.com/Authress/authress-sdk.php/tar.gz/refs/heads/release/0.3","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225184043,"owners_count":17434243,"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-18T13:34:23.352Z","updated_at":"2024-11-18T13:34:24.510Z","avatar_url":"https://github.com/Authress.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp id=\"main\" align=\"center\"\u003e\n  \u003cimg src=\"https://authress.io/static/images/linkedin-banner.png\" alt=\"Authress media banner\"\u003e\n\u003c/p\u003e\n\n# Authress SDK for PHP\n\n## Installation \u0026 Usage\nInstall authress-sdk for usage of the API:\n\n`composer require authress/authress-sdk.php`\n\n## SDK usage\n\nThere's a full working example in this repository for how to flow can look like: [working example](./integrationTest/mock/index.php);\n\nThe full flow is usually:\n* Check if user is logged in using `userSessionExists`\n* If user is not logged in send them to your login page\n  * On your login page ask the user which connection provider they want to use\n  * Call `authenticate` with that `connectionId`\n  * User will be redirected to the provider\n* User will be returned to your redirectUrl\n  * The redirectUrl page should include a code snippet from the [working example](./integrationTest/mock/index.php) and in the URL of your page will contain the `iss`, `code`, and `nonce` parameters (for validation, you don't need to worry how to handle them, but they need to be there this signals that the login worked correctly.)\n* Call the `userSessionExists` method\n  * This should work and return `true` at this moment\n\n  You can also validate this worked by looking at the cookies for the app, which should contain `authorization` and `user` cookies. Please don't use these cookies directly as their format might change.\n\n### Authorization\n\n```php\n\u003c?php\nrequire('vendor/autoload.php');\nuse AuthressSdk\\AuthressClient;\nuse AuthressSdk\\ApiException;\n\n// create an instance of the API class during service initialization\n$authressCustomDomain = \"https://login.application.com\";\n$authressClient = new AuthressClient($authressCustomDomain);\n$authressClient-\u003esetApiKey('eyJ...');\n\n// OR: Set the user's access token per request\n$authressClient-\u003esetAccessToken(\"user-JWT\");\n\n$apiInstance = new \\AuthressSdk\\Api\\UserPermissionsApi($authressClient);\n\ntry {\n    $userId = \"test-userId\";\n    $resourceUri = \"test-resource\";\n    $permission = \"test-permission\";\n    $result = $apiInstance-\u003eauthorizeUser($userId, $resourceUri, $permission);\n} catch (ApiException $e) {\n    if ($e-\u003egetStatusCode() === 404 || $e-\u003egetStatusCode() === 403) {\n        return false;\n    }\n    throw $e;\n}\n?\u003e\n```\n\n### Authentication\n\nLog the user in with the selected identity provider connection. Use when the user isn't logged in yet.\n\n```php\n\u003c?php\nrequire('vendor/autoload.php');\nuse AuthressSdk\\AuthressClient;\nuse AuthressSdk\\Login\\AuthenticationParameters;\n\n// create an instance of the API class during service initialization: https://authress.io/app/#/setup?focus=domain\n$authressCustomDomain = \"https://login.application.com\";\n// The application that the user is logging in with https://authress.io/app/#/setup?focus=applications\n$applicationId = 'app_APPLICATION_ID';\n$authressClient = new AuthressClient($authressCustomDomain, $applicationId);\n\n$options = new AuthenticationParameters([\n    // When user clicks \"Log in with Google (or Github)\" pass the relevant connectionId here:  https://authress.io/app/#/setup?focus=connections\n    'connectionId' =\u003e \"CONNECTION_ID\",\n    // Optional redirect, by default the redirect url will be the current window.location.href\n    'redirectUrl' =\u003e \"URL_AFTER_SUCCESS_LOGIN\"\n]);\n\n// Returns true if the user is successfully logged in, and otherwise redirects the user to appropriate login page\nsession_start();\n$result = $authressClient-\u003elogin-\u003eauthenticate($options);\n?\u003e\n```\n\nCheck if the user is currently logged in. If the user isn't logged in yet, call `$authressClient-\u003elogin-\u003eauthenticate()` above.\n\n```php\n\u003c?php\nrequire('vendor/autoload.php');\nuse AuthressSdk\\AuthressClient;\n\n// create an instance of the API class during service initialization: https://authress.io/app/#/setup?focus=domain\n$authressCustomDomain = \"https://login.application.com\";\n// The application that the user is logging in with https://authress.io/app/#/setup?focus=applications\n$applicationId = \"app_APPLICATION_ID\";\n$authressClient = new AuthressClient($authressCustomDomain, $applicationId);\n\n// Returns true if the user is successfully logged in, and otherwise redirects the user to appropriate login page.\nsession_start();\n$isUserLoggedIn = $authressClient-\u003elogin-\u003euserSessionExists();\nif (!$isUserLoggedIn) {\n    // When the user isn't logged in, send them to the login page\n    header(\"Location: ./login.php\");\n    exit();\n}\n\n// Optionally get access to the user's authorization access token, this token can be explicitly used to call other APIs including Authress authorization as the user.\n$userToken = $authressClient-\u003elogin-\u003egetToken();\n\n?\u003e\n```\n\nVerify an incoming token into your service from a client:\n\n```php\n\u003c?php\nrequire('vendor/autoload.php');\nuse AuthressSdk\\AuthressClient;\n\n// create an instance of the API class during service initialization: https://authress.io/app/#/setup?focus=domain\n$authressCustomDomain = \"https://login.application.com\";\n// The application that the user is logging in with https://authress.io/app/#/setup?focus=applications\n$applicationId = \"app_APPLICATION_ID\";\n$authressClient = new AuthressClient($authressCustomDomain, $applicationId);\n\n// Returns true if the user is successfully logged in, and otherwise redirects the user to appropriate login page.\nsession_start();\n$token = $authressClient-\u003elogin-\u003egetToken();\n$accessTokenClaims = $authressClient-\u003elogin-\u003everifyToken($token);\necho json_encode($accessTokenClaims);\n\n// Or set it as the `Authorization Header` to call another service:\n\n$client-\u003erequest('POST', 'https://api.application.com', [\n    headers =\u003e [\n        'Authorization' =\u003e 'Bearer ' . $token\n    ]\n]);\n\n?\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthress%2Fauthress-sdk.php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauthress%2Fauthress-sdk.php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthress%2Fauthress-sdk.php/lists"}