{"id":39453554,"url":"https://github.com/oakhope/oauth2-wechat","last_synced_at":"2026-01-18T04:32:28.983Z","repository":{"id":57029711,"uuid":"102416817","full_name":"oakhope/oauth2-wechat","owner":"oakhope","description":"微信登录认证授权 Wechat login authorization. This package provides Wechat OAuth 2.0 support for the PHP League's OAuth 2.0 Client","archived":false,"fork":false,"pushed_at":"2017-09-15T10:49:02.000Z","size":2044,"stargazers_count":20,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-10T21:48:33.845Z","etag":null,"topics":["authorisation","authorization","client","login","oauth","oauth2","wechat","wexin"],"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/oakhope.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-05T01:05:32.000Z","updated_at":"2024-03-08T09:44:11.000Z","dependencies_parsed_at":"2022-08-23T17:41:04.753Z","dependency_job_id":null,"html_url":"https://github.com/oakhope/oauth2-wechat","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/oakhope/oauth2-wechat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oakhope%2Foauth2-wechat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oakhope%2Foauth2-wechat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oakhope%2Foauth2-wechat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oakhope%2Foauth2-wechat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oakhope","download_url":"https://codeload.github.com/oakhope/oauth2-wechat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oakhope%2Foauth2-wechat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28529689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"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":["authorisation","authorization","client","login","oauth","oauth2","wechat","wexin"],"created_at":"2026-01-18T04:32:28.881Z","updated_at":"2026-01-18T04:32:28.959Z","avatar_url":"https://github.com/oakhope.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wechat Provider for OAuth 2.0 Client\n\n[![Latest Version](https://img.shields.io/github/release/oakhope/oauth2-wechat.svg?style=flat-square)](https://github.com/oakhope/oauth2-wechat/releases)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![Build Status](https://img.shields.io/travis/oakhope/oauth2-wechat/master.svg?style=flat-square)](https://travis-ci.org/oakhope/oauth2-wechat)\n[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/oakhope/oauth2-wechat.svg?style=flat-square)](https://scrutinizer-ci.com/g/oakhope/oauth2-wechat/code-structure)\n[![Quality Score](https://img.shields.io/scrutinizer/g/oakhope/oauth2-wechat.svg?style=flat-square)](https://scrutinizer-ci.com/g/oakhope/oauth2-wechat)\n[![Total Downloads](https://img.shields.io/packagist/dt/oakhope/oauth2-wechat.svg?style=flat-square)](https://packagist.org/packages/oakhope/oauth2-wechat)\n\nThis package provides Wechat OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).\n\n- DONE:\n    \u003e Website SDK, Mini Programs\n\n- TODO: \n    \u003e Mobile App SDK \n\n## Installation\n\nTo install, use composer:\n\n```\ncomposer require oakhope/oauth2-wechat\n```\n\n## Usage\n\nUsage is the same as The League's OAuth client, using `\\Oakhope\\OAuth2\\Client\\Provider\\{WebProvider}` as the provider.\n\n### Authorization Code Flow\n\n```php\n$provider = new \\Oakhope\\OAuth2\\Client\\Provider\\WebProvider([\n        'appid' =\u003e '{wechat-client-id}',\n        'secret' =\u003e '{wechat-client-secret}',\n        'redirect_uri' =\u003e 'https://example.com/callback-url'\n    ]);\n\n// If we don't have an authorization code then get one\nif (!isset($_GET['code'])) {\n\n    // Fetch the authorization URL from the provider; this returns the\n    // urlAuthorize option and generates and applies any necessary parameters\n    // (e.g. state).\n    $authorizationUrl = $provider-\u003egetAuthorizationUrl();\n\n    // Get the state generated for you and store it to the session.\n    $_SESSION['oauth2state'] = $provider-\u003egetState();\n\n    // Redirect the user to the authorization URL.\n    header('Location: '.$authorizationUrl);\n    exit;\n\n// Check given state against previously stored one to mitigate CSRF attack\n} elseif (empty($_GET['state']) || ($_GET['state'] !== rtrim($_SESSION['oauth2state'], '#wechat_redirect'))) {\n\n    unset($_SESSION['oauth2state']);\n    exit('Invalid state');\n\n} else {\n\n    try {\n\n        // Try to get an access token using the authorization code grant.\n        $accessToken = $provider-\u003egetAccessToken(\n            'authorization_code',\n            [\n                'code' =\u003e $_GET['code'],\n            ]);\n\n        // We have an access token, which we may use in authenticated\n        // requests against the service provider's API.\n        echo \"token: \".$accessToken-\u003egetToken().\"\u003cbr/\u003e\";\n        echo \"refreshToken: \".$accessToken-\u003egetRefreshToken().\"\u003cbr/\u003e\";\n        echo \"Expires: \".$accessToken-\u003egetExpires().\"\u003cbr/\u003e\";\n        echo ($accessToken-\u003ehasExpired() ? 'expired' : 'not expired').\"\u003cbr/\u003e\u003cbr/\u003e\";\n\n        // Using the access token, we may look up details about the\n        // resource owner.\n        $resourceOwner = $provider-\u003egetResourceOwner($accessToken);\n\n        var_export($resourceOwner-\u003etoArray());\n        \n    } catch (\\League\\OAuth2\\Client\\Provider\\Exception\\IdentityProviderException $e) {\n\n        // Failed to get the access token or user details.\n        echo \"error:\";\n        exit($e-\u003egetMessage());\n    }\n}\n```\n\n\n### Refreshing a Token\n\nOnce your application is authorized, you can refresh an expired token using a refresh token rather than going through the entire process of obtaining a brand new token. To do so, simply reuse this refresh token from your data store to request a refresh.\n\n_This example uses [Brent Shaffer's](https://github.com/bshaffer) demo OAuth 2.0 application named **Lock'd In**. See authorization code example above, for more details._\n\n```php\n$provider = new \\Oakhope\\OAuth2\\Client\\Provider\\WebProvider([\n        'appid' =\u003e '{wechat-client-id}',\n        'secret' =\u003e '{wechat-client-secret}',\n        'redirect_uri' =\u003e 'https://example.com/callback-url'\n    ]);\n\n$existingAccessToken = getAccessTokenFromYourDataStore();\n\nif ($existingAccessToken-\u003ehasExpired()) {\n    $newAccessToken = $provider-\u003egetAccessToken('refresh_token', [\n        'refresh_token' =\u003e $existingAccessToken-\u003egetRefreshToken()\n    ]);\n\n    // Purge old access token and store new access token to your data store.\n}\n```\n\n## Testing\n\n``` bash\n$ ./vendor/bin/phpunit --colors tests\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/oakhope/oauth2-wechat/blob/master/CONTRIBUTING.md) for details.\n\n\n## Credits\n\n- [Benji Wang](https://github.com/oakhope)\n- [All Contributors](https://github.com/oakhope/oauth2-wechat/contributors)\n\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/oakhope/oauth2-wechat/blob/master/LICENSE) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foakhope%2Foauth2-wechat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foakhope%2Foauth2-wechat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foakhope%2Foauth2-wechat/lists"}