Skip to content

Commit

Permalink
Add Indeed OAuth Provider (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahapranta committed Jan 26, 2024
0 parents commit 97db9a0
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
18 changes: 18 additions & 0 deletions IndeedExtendSocialite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SocialiteProviders\Indeed;

use SocialiteProviders\Manager\SocialiteWasCalled;

class IndeedExtendSocialite
{
/**
* Register the provider.
*
* @param SocialiteWasCalled $socialiteWasCalled
*/
public function handle(SocialiteWasCalled $socialiteWasCalled): void
{
$socialiteWasCalled->extendSocialite('indeed', Provider::class);
}
}
57 changes: 57 additions & 0 deletions Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace SocialiteProviders\Indeed;

use GuzzleHttp\RequestOptions;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
use SocialiteProviders\Manager\OAuth2\User;

class Provider extends AbstractProvider
{
public const IDENTIFIER = 'INDEED';

/**
* {@inheritdoc}
*/
protected $scopeSeparator = ' ';

protected $scopes = ['email', 'offline_access'];

/**
* @inheritDoc
*/
protected function getAuthUrl($state)
{
return $this->buildAuthUrlFromBase('https://secure.indeed.com/oauth/v2/authorize', $state);
}

/**
* @inheritDoc
*/
protected function getTokenUrl()
{
return "https://apis.indeed.com/oauth/v2/tokens";
}

/**
* @inheritDoc
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->get('https://secure.indeed.com/v2/api/userinfo', [
RequestOptions::HEADERS => [
'Authorization' => 'Bearer ' . $token,
],
]);

return json_decode($response->getBody(), true);
}

/**
* @inheritDoc
*/
protected function mapUserToObject(array $user)
{
return (new User())->setRaw($user);
}
}
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Discord

```bash
composer require socialiteproviders/indeed
```

## Installation & Basic Usage

Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below.

### Add configuration to `config/services.php`

```php
'indeed' => [
'client_id' => env('INDEED_CLIENT_ID'),
'client_secret' => env('INDEED_CLIENT_SECRET'),
'redirect' => env('INDEED_REDIRECT_URI'),
],
```

### Add provider event listener

Configure the package's listener to listen for `SocialiteWasCalled` events.

Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.

```php
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// ... other providers
\SocialiteProviders\Indeed\IndeedExtendSocialite::class.'@handle',
],
];
```

### Usage

You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):

```php
return Socialite::driver('indeed')->redirect();
```

### Returned User fields

- ``sub`` (**string**) Unique identifier for the user's account. e.g. `248289761001`
- ``email`` (**string**) User's email address.
- ``email_verified`` (**boolean**) Indicates whether the user has verified their email address. e.g. `true`
33 changes: 33 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "socialiteproviders/indeed",
"description": "Indeed OAuth2 Provider for Laravel Socialite",
"license": "MIT",
"keywords": [
"indeed",
"laravel",
"oauth",
"provider",
"socialite"
],
"authors": [
{
"name": "Pranta Saha",
"email": "pranta1204@gmail.com"
}
],
"support": {
"issues": "https://github.com/socialiteproviders/providers/issues",
"source": "https://github.com/socialiteproviders/providers",
"docs": "https://socialiteproviders.com/indeed"
},
"require": {
"php": "^8.0",
"ext-json": "*",
"socialiteproviders/manager": "^4.4"
},
"autoload": {
"psr-4": {
"SocialiteProviders\\Indeed\\": ""
}
}
}

0 comments on commit 97db9a0

Please sign in to comment.