|
1 | | -"# third-party" |
| 1 | +# Effectra ThirdParty Library |
| 2 | + |
| 3 | +Effectra\ThirdParty is a PHP library that provides OAuth configuration and functionality for various third-party platforms such as LinkedIn, GitHub, Facebook, and Google. It simplifies the process of integrating with these platforms and accessing user data through OAuth authentication. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Simplified OAuth configuration and authentication for third-party platforms. |
| 8 | +- Easy retrieval of access tokens and user information. |
| 9 | +- Supports multiple popular platforms like LinkedIn, GitHub, Facebook, and Google. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +You can install the Effectra\ThirdParty library via Composer. Run the following command in your project directory: |
| 14 | + |
| 15 | +```shell |
| 16 | +composer require effectra/third-party |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### LinkedIn |
| 22 | + |
| 23 | +To use the LinkedIn OAuth functionality, follow these steps: |
| 24 | + |
| 25 | +1. Create an instance of the `LinkedIn` class by providing your LinkedIn client ID, client secret, and optional redirect URL and scopes. |
| 26 | + |
| 27 | +```php |
| 28 | +use Effectra\ThirdParty\LinkedIn; |
| 29 | + |
| 30 | +$linkedin = new LinkedIn('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URL', ['r_liteprofile', 'r_emailaddress']); |
| 31 | +``` |
| 32 | + |
| 33 | +2. Generate the authorization URL to redirect the user for authentication: |
| 34 | + |
| 35 | +```php |
| 36 | +$authUrl = $linkedin->getAuthURL(); |
| 37 | +``` |
| 38 | + |
| 39 | +3. Redirect the user to the generated authorization URL. After successful authentication, LinkedIn will redirect the user back to the specified redirect URL with an authorization code. |
| 40 | + |
| 41 | +4. Exchange the authorization code for an access token: |
| 42 | + |
| 43 | +```php |
| 44 | +$code = $_GET['code']; // The authorization code obtained from the LinkedIn redirect |
| 45 | +$accessToken = $linkedin->getAccessToken($code); |
| 46 | +``` |
| 47 | + |
| 48 | +5. Use the access token to retrieve user information: |
| 49 | + |
| 50 | +```php |
| 51 | +$user = $linkedin->getUser($accessToken); |
| 52 | +``` |
| 53 | + |
| 54 | +### GitHub |
| 55 | + |
| 56 | +To use the GitHub OAuth functionality, follow these steps: |
| 57 | + |
| 58 | +1. Create an instance of the `GitHub` class by providing your GitHub client ID, client secret, and optional redirect URL and scopes. |
| 59 | + |
| 60 | +```php |
| 61 | +use Effectra\ThirdParty\GitHub; |
| 62 | + |
| 63 | +$github = new GitHub('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URL', ['user']); |
| 64 | +``` |
| 65 | + |
| 66 | +2. Generate the authorization URL to redirect the user for authentication: |
| 67 | + |
| 68 | +```php |
| 69 | +$authUrl = $github->getAuthURL(); |
| 70 | +``` |
| 71 | + |
| 72 | +3. Redirect the user to the generated authorization URL. After successful authentication, GitHub will redirect the user back to the specified redirect URL with an authorization code. |
| 73 | + |
| 74 | +4. Exchange the authorization code for an access token: |
| 75 | + |
| 76 | +```php |
| 77 | +$code = $_GET['code']; // The authorization code obtained from the GitHub redirect |
| 78 | +$accessToken = $github->getAccessToken($code); |
| 79 | +``` |
| 80 | + |
| 81 | +5. Use the access token to retrieve user information: |
| 82 | + |
| 83 | +```php |
| 84 | +$user = $github->getUser($accessToken); |
| 85 | +``` |
| 86 | + |
| 87 | +### Facebook |
| 88 | + |
| 89 | +To use the Facebook OAuth functionality, follow these steps: |
| 90 | + |
| 91 | +1. Create an instance of the `Facebook` class by providing your Facebook client ID, client secret, and optional redirect URL and scopes. |
| 92 | + |
| 93 | +```php |
| 94 | +use Effectra\ThirdParty\Facebook; |
| 95 | + |
| 96 | +$facebook = new Facebook('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URL', ['email']); |
| 97 | +``` |
| 98 | + |
| 99 | +2. Generate the authorization URL to redirect the user for authentication: |
| 100 | + |
| 101 | +```php |
| 102 | +$authUrl = $facebook->getAuthURL(); |
| 103 | +``` |
| 104 | + |
| 105 | +3. Redirect the user to the generated authorization URL. After successful authentication, Facebook will redirect the user back to the specified redirect URL with an authorization code. |
| 106 | + |
| 107 | +4. Exchange the authorization code for an access token: |
| 108 | + |
| 109 | +```php |
| 110 | +$code = $_GET['code']; // The authorization code obtained from the Facebook redirect |
| 111 | +$accessToken = $facebook->getAccessToken($code); |
| 112 | +``` |
| 113 | + |
| 114 | +5 |
| 115 | + |
| 116 | +. Use the access token to retrieve user information: |
| 117 | + |
| 118 | +```php |
| 119 | +$user = $facebook->getUser($accessToken); |
| 120 | +``` |
| 121 | + |
| 122 | +### Google |
| 123 | + |
| 124 | +To use the Google OAuth functionality, follow these steps: |
| 125 | + |
| 126 | +1. Create an instance of the `Google` class by providing your Google client ID, client secret, and optional redirect URL and scopes. |
| 127 | + |
| 128 | +```php |
| 129 | +use Effectra\ThirdParty\Google; |
| 130 | + |
| 131 | +$google = new Google('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URL', ['profile', 'email']); |
| 132 | +``` |
| 133 | + |
| 134 | +2. Generate the authorization URL to redirect the user for authentication: |
| 135 | + |
| 136 | +```php |
| 137 | +$authUrl = $google->getAuthURL(); |
| 138 | +``` |
| 139 | + |
| 140 | +3. Redirect the user to the generated authorization URL. After successful authentication, Google will redirect the user back to the specified redirect URL with an authorization code. |
| 141 | + |
| 142 | +4. Exchange the authorization code for an access token: |
| 143 | + |
| 144 | +```php |
| 145 | +$code = $_GET['code']; // The authorization code obtained from the Google redirect |
| 146 | +$accessToken = $google->getAccessToken($code); |
| 147 | +``` |
| 148 | + |
| 149 | +5. Use the access token to retrieve user information: |
| 150 | + |
| 151 | +```php |
| 152 | +$user = $google->getUser($accessToken); |
| 153 | +``` |
| 154 | + |
| 155 | +## License |
| 156 | + |
| 157 | +This library is open source and available under the [MIT License](LICENSE). |
| 158 | + |
| 159 | +## Contribution |
| 160 | + |
| 161 | +Contributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request. |
| 162 | + |
| 163 | +## Credits |
| 164 | + |
| 165 | +This library is developed and maintained by Effectra. You can find more information about us on our website: [www.effectra.com](https://www.effectra.com/) |
| 166 | + |
| 167 | +## Contact |
| 168 | + |
| 169 | +For any inquiries or questions, you can reach us at [info@effectra.com](mailto:info@effectra.com) |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +Feel free to modify and customize this README file according to your specific needs. |
0 commit comments