{"id":16296704,"url":"https://github.com/hernandev/oauth2-sc2","last_synced_at":"2025-10-13T10:14:22.123Z","repository":{"id":62515980,"uuid":"123469357","full_name":"hernandev/oauth2-sc2","owner":"hernandev","description":"SteemConnect V2 OAuth library for PHP, built as a League's OAuth Provider.","archived":false,"fork":false,"pushed_at":"2018-04-17T09:39:59.000Z","size":56,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-21T04:39:58.536Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hernandev.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-03-01T17:33:37.000Z","updated_at":"2020-08-06T03:37:57.000Z","dependencies_parsed_at":"2022-11-02T13:03:35.824Z","dependency_job_id":null,"html_url":"https://github.com/hernandev/oauth2-sc2","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/hernandev/oauth2-sc2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernandev%2Foauth2-sc2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernandev%2Foauth2-sc2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernandev%2Foauth2-sc2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernandev%2Foauth2-sc2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hernandev","download_url":"https://codeload.github.com/hernandev/oauth2-sc2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernandev%2Foauth2-sc2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014681,"owners_count":26085554,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-10T20:23:43.222Z","updated_at":"2025-10-13T10:14:22.107Z","avatar_url":"https://github.com/hernandev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## SteemConnect V2: OAuth2 Client / Provider\n\n[![Build Status](https://travis-ci.org/hernandev/oauth2-sc2.svg?branch=master)](https://travis-ci.org/hernandev/oauth2-sc2)\n[![Codecov](https://codecov.io/gh/hernandev/oauth2-sc2/branch/master/graph/badge.svg)](https://codecov.io/gh/hernandev/oauth2-sc2)\n[![Latest Stable Version](https://poser.pugx.org/hernandev/oauth2-sc2/v/stable)](https://packagist.org/packages/hernandev/oauth2-sc2)\n[![License](https://poser.pugx.org/hernandev/oauth2-sc2/license)](https://packagist.org/packages/hernandev/oauth2-sc2)\n\nThis library is a simple, easy implement OAuth2 client for SteemConnect V2 clients.\n\nIt takes the pain from integrating and parsing all the specifics and delivers a great authorization flow for those who aim to handle authorization through SteemConnect V2.\n\n### 0. Why?\n\nWell, OAuth2 is not that complicated, this project started while building a SteemConnect V2 SDK for PHP, so this project is the Authorization part of another package coming on the next days.\n\n### 1. Installation.\n\nAll you need to do is install this library as a dependency on your project, through composer:\n\n```bash\ncomposer require hernandev/oauth2-sc2\n```\n\n### 2. Usage:\n\nBefore using thins library, keep in mind you'll need a SteemConnect application client ID and secret.\n\n#### 2.1. Configuring:\n\nIt could not be more simple. Just create a config instance, passing your application credentials:\n\n```php\nuse SteemConnect\\OAuth2\\Config\\Config;\n\n// creates the configuration object:\n$config = new Config('your.app', 'your-long-secret-id-here-keep-it-secret');\n\n```\n\nAfter setting your credentials, you will need to decide with scopes you will ask permission to:\n\n```php\n// set the scopes you want.\n$config-\u003esetScopes([\n    'login', 'vote', 'comment', 'comment_delete'\n]);\n```\n\nIf you are not sure about the scopes you will need, those are documented on the SteemConnect wiki.\n\nFinally, we will configure, to which URL the user should return, after granting you the permissions:\n\n```php\n// set the return / callback URL.\n$config-\u003esetReturnUrl('https://my-steem-app-is-awesome.com/login/return');\n```\n\n#### 2.2. Redirecting to Authorization:\n\nThat was really, all you need to configure to use the library, pretty cool ham?\n\nNow, of course, you need to redirect the users, to SteemConnect where they will authorize you to act on their behalf.\n\n```php\nuse SteemConnect\\OAuth2\\Provider\\Provider;\n\n// first, we create a provider instance, passing the configuration needed:\n$provider = new Provider($config);\n```\n\n// finally, we can get the redirect URL, so we can send users to SteemConnect:\n\n```php\n// get the URL string that you will redirect to.\n$provider-\u003egetAuthorizationUrl()\n```\n\n#### 2.3. Parsing the Return:\n\nGuess what? super hard to do:\n\nYou will need both the config and provider code used before, so I assume you will be clever and put that logic on a common place.\n\n```php\n// just call the parse return URL and this library will automatically exchange the access code by the actual token: \n$token = $provider-\u003eparseReturn();\n```\n\nOn the previous call, $token is an instance of `AccessToken` class, which can be used for the following things:\n\n```php\n// gets the actual token that will be used on requests.\n$token-\u003egetToken();\n\n// gets the expiration date, so you know the token is no longer valid.\n$token-\u003egetExpires();\n\n// gets the refresh token, which may be used to issue a new token, if the offline scope was requested.\n$token-\u003egetRefreshToken();\n\n// gets the standard ID for the account authorizing your app, it means, this field retrieves the account @username\n$token-\u003egetResourceOwnerId();\n```\n\n#### 2.4. Storing Tokens.\n\nAfter obtained a given user's Access Token, in most cases, you will need to store the tokens for later usage.\n\nWhatever the approach for storing the tokens (browser session / database), you will need to serialize\nthe tokens and later, decode then.\n\nThis can be easily done, by two methods on the Provider:\n\nEncoding:\n\n```php\n// encode the AccessToken instance into a JSON string.\n$tokenJson = $provider-\u003eencodeToken($token);\n```\n\nDecoding:\n\n```php\n// decode the JSON string token back into a AccessToken instance.\n$token = $provider-\u003edecodeToken($tokenJson);\n```\n\n#### 2.5. Refreshing Expired Tokens.\n\nWhenever the `offline` scope is used to issue a token, the resulting `AccessToken` instance will contain\na field called `refresh_token. The refresh token can be used for issuing a new one.\n\nTo issue a new token, using a existing one, that contains a refresh token, just do:\n\n```php\n// get a new token from the existing / expired one.\n$newToken = $provider-\u003erefreshToken($token);\n```\n\nOR\n\nIf you only stored the refresh_token field value, you may use that string directly, by doing:\n\n\n```php\n// get a new AccessToken using the refresh token string.\n$token = $provider-\u003erefreshTokenString($refreshTokenString);  \n```\n\n#### 2.5. Extras:\n\nOf course there are extras!\n\nThis library implements the `ResourceOwner` interface, which means you can also query right away some information about the account which granted you permissions:\n\n```php\n// gets the resource owner instance.\n$owner = $provider-\u003egetResourceOwner($token);\n\n// now you can use any key you may see on steemd.com directly on that $owner object!!!\n\n$owner-\u003eprofile_json;\n$owner-\u003ebalance;\n$owner-\u003ereputation;\n// and so on...\n```\n\n**That's All Folks!**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhernandev%2Foauth2-sc2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhernandev%2Foauth2-sc2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhernandev%2Foauth2-sc2/lists"}