{"id":19167206,"url":"https://github.com/dyweb/oauth2-jaccount","last_synced_at":"2025-05-07T13:40:40.620Z","repository":{"id":56973883,"uuid":"186964188","full_name":"dyweb/oauth2-jaccount","owner":"dyweb","description":"jAccount OAuth 2.0 support for the PHP League's OAuth 2.0 Client","archived":false,"fork":false,"pushed_at":"2019-05-16T07:12:10.000Z","size":9,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-02T16:12:19.967Z","etag":null,"topics":["jaccount","oauth2","sjtu"],"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/dyweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-16T06:21:19.000Z","updated_at":"2019-11-09T16:36:26.000Z","dependencies_parsed_at":"2022-08-21T07:10:15.607Z","dependency_job_id":null,"html_url":"https://github.com/dyweb/oauth2-jaccount","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyweb%2Foauth2-jaccount","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyweb%2Foauth2-jaccount/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyweb%2Foauth2-jaccount/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyweb%2Foauth2-jaccount/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dyweb","download_url":"https://codeload.github.com/dyweb/oauth2-jaccount/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252888841,"owners_count":21820075,"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":["jaccount","oauth2","sjtu"],"created_at":"2024-11-09T09:36:18.886Z","updated_at":"2025-05-07T13:40:40.598Z","avatar_url":"https://github.com/dyweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JAccount Provider for OAuth 2.0 Client\n\nThis package provides JAccount OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).\n\n## Installation\n\n```\ncomposer require dyweb/oauth2-jaccount\n```\n\n## Usage\n\n```php\n$provider = new \\Dyweb\\OAuth2\\Client\\Provider\\JAccount([\n    'clientId'                =\u003e 'yourId',          // The client ID assigned to you by NIC\n    'clientSecret'            =\u003e 'yourSecret',      // The client password assigned to you by NIC\n    'redirectUri'             =\u003e 'yourUrl'          // The return URL you specified for your app on NIC\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']) || (isset($_SESSION['oauth2state']) \u0026\u0026 $_GET['state'] !== $_SESSION['oauth2state'])) {\n\n    if (isset($_SESSION['oauth2state'])) {\n        unset($_SESSION['oauth2state']);\n    }\n\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('authorization_code', [\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 'Access Token: ' . $accessToken-\u003egetToken() . \"\u003cbr\u003e\";\n        echo 'Refresh Token: ' . $accessToken-\u003egetRefreshToken() . \"\u003cbr\u003e\";\n        echo 'Expired in: ' . $accessToken-\u003egetExpires() . \"\u003cbr\u003e\";\n        echo 'Already expired? ' . ($accessToken-\u003ehasExpired() ? 'expired' : 'not expired') . \"\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        exit($e-\u003egetMessage());\n\n    }\n\n}\n```\n\nFor more information see the PHP League's general usage examples.\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/michaelKaefer/oauth2-amazon/blob/master/LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdyweb%2Foauth2-jaccount","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdyweb%2Foauth2-jaccount","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdyweb%2Foauth2-jaccount/lists"}