Skip to content

Commit 993eb4f

Browse files
committed
fix: update ClickUp API URLs to use the new subdomain url (SocialiteProviders#1366)
1 parent 089b0ae commit 993eb4f

5 files changed

Lines changed: 211 additions & 3 deletions

File tree

src/ClickUp/Provider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,26 @@ class Provider extends AbstractProvider
1010
{
1111
public const IDENTIFIER = 'CLICKUP';
1212

13+
protected const BASE_URL = 'https://api.clickup.com/api';
14+
1315
protected $scopes = ['profile'];
1416

1517
protected function getAuthUrl($state): string
1618
{
17-
return $this->buildAuthUrlFromBase('https://app.clickup.com/api', $state);
19+
return $this->buildAuthUrlFromBase(self::BASE_URL, $state);
1820
}
1921

2022
protected function getTokenUrl(): string
2123
{
22-
return 'https://app.clickup.com/api/v2/oauth/token';
24+
return self::BASE_URL.'/v2/oauth/token';
2325
}
2426

2527
/**
2628
* {@inheritdoc}
2729
*/
2830
protected function getUserByToken($token)
2931
{
30-
$response = $this->getHttpClient()->get('https://app.clickup.com/api/v2/user', [
32+
$response = $this->getHttpClient()->get(self::BASE_URL.'/v2/user', [
3133
RequestOptions::HEADERS => [
3234
'Authorization' => $token,
3335
],
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace SocialiteProviders\Crowdin;
4+
5+
use SocialiteProviders\Manager\SocialiteWasCalled;
6+
7+
class CrowdinExtendSocialite
8+
{
9+
public function handle(SocialiteWasCalled $socialiteWasCalled): void
10+
{
11+
$socialiteWasCalled->extendSocialite('crowdin', Provider::class);
12+
}
13+
}

src/Crowdin/Provider.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace SocialiteProviders\Crowdin;
4+
5+
use GuzzleHttp\RequestOptions;
6+
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
7+
use SocialiteProviders\Manager\OAuth2\User;
8+
9+
class Provider extends AbstractProvider
10+
{
11+
public const IDENTIFIER = 'CROWDIN';
12+
13+
protected $scopes = [];
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected $consent = false;
19+
20+
protected $scopeSeparator = ' ';
21+
22+
protected function getAuthUrl($state): string
23+
{
24+
return $this->buildAuthUrlFromBase('https://accounts.crowdin.com/oauth/authorize', $state);
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function getCodeFields($state = null)
31+
{
32+
$fields = parent::getCodeFields($state);
33+
34+
if (! $this->consent) {
35+
$fields['prompt'] = 'none';
36+
}
37+
38+
return $fields;
39+
}
40+
41+
/**
42+
* Prompt for consent each time or not.
43+
*
44+
* @return $this
45+
*/
46+
public function withConsent()
47+
{
48+
$this->consent = true;
49+
50+
return $this;
51+
}
52+
53+
protected function getTokenUrl(): string
54+
{
55+
return 'https://accounts.crowdin.com/oauth/token';
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
protected function getUserByToken($token)
62+
{
63+
$response = $this->getHttpClient()->get(
64+
'https://crowdin.com/api/v2/user',
65+
[
66+
RequestOptions::HEADERS => [
67+
'Authorization' => 'Bearer '.$token,
68+
],
69+
]
70+
);
71+
72+
return json_decode((string) $response->getBody(), true);
73+
}
74+
75+
/**
76+
* {@inheritdoc}
77+
*/
78+
protected function mapUserToObject(array $user)
79+
{
80+
return (new User)->setRaw($user)->map([
81+
'id' => $user['id'],
82+
'nickname' => $user['fullName'],
83+
'name' => $user['username'],
84+
'email' => $user['email'] ?? null,
85+
'avatar' => $user['avatarUrl'],
86+
]);
87+
}
88+
}

src/Crowdin/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Crowdin
2+
3+
```bash
4+
composer require socialiteproviders/crowdin
5+
```
6+
7+
## Installation & Basic Usage
8+
9+
Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below.
10+
11+
### Add configuration to `config/services.php`
12+
13+
```php
14+
'crowdin' => [
15+
'client_id' => env('CROWDIN_CLIENT_ID'),
16+
'client_secret' => env('CROWDIN_CLIENT_SECRET'),
17+
'redirect' => env('CROWDIN_REDIRECT_URI'),
18+
19+
// optional
20+
'allow_gif_avatars' => (bool)env('CROWDIN_AVATAR_GIF', true),
21+
'avatar_default_extension' => env('CROWDIN_EXTENSION_DEFAULT', 'png'), // only pick from jpg, png, webp
22+
],
23+
```
24+
25+
### Add provider event listener
26+
27+
#### Laravel 11+
28+
29+
In Laravel 11, the default `EventServiceProvider` provider was removed. Instead, add the listener using the `listen` method on the `Event` facade, in your `AppServiceProvider` `boot` method.
30+
31+
* Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.
32+
33+
```php
34+
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
35+
$event->extendSocialite('crowdin', \SocialiteProviders\Crowdin\Provider::class);
36+
});
37+
```
38+
<details>
39+
<summary>
40+
Laravel 10 or below
41+
</summary>
42+
Configure the package's listener to listen for `SocialiteWasCalled` events.
43+
44+
Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.
45+
46+
```php
47+
protected $listen = [
48+
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
49+
// ... other providers
50+
\SocialiteProviders\Crowdin\CrowdinExtendSocialite::class.'@handle',
51+
],
52+
];
53+
```
54+
</details>
55+
56+
### Usage
57+
58+
You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):
59+
60+
```php
61+
return Socialite::driver('crowdin')->redirect();
62+
```
63+
64+
### Returned User fields
65+
66+
- ``id``
67+
- ``nickname``
68+
- ``name``
69+
- ``email``
70+
- ``avatar``

src/Crowdin/composer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "socialiteproviders/crowdin",
3+
"description": "Crowdin OAuth2 Provider for Laravel Socialite",
4+
"license": "MIT",
5+
"keywords": [
6+
"crowdin",
7+
"laravel",
8+
"oauth",
9+
"provider",
10+
"socialite"
11+
],
12+
"authors": [
13+
{
14+
"name": "WentTheFox",
15+
"email": "mail@went.tf",
16+
"homepage": "https://went.tf",
17+
"role": "developer"
18+
}
19+
],
20+
"support": {
21+
"issues": "https://github.com/socialiteproviders/providers/issues",
22+
"source": "https://github.com/socialiteproviders/providers",
23+
"docs": "https://socialiteproviders.com/crowdin"
24+
},
25+
"require": {
26+
"php": "^8.0",
27+
"ext-json": "*",
28+
"socialiteproviders/manager": "^4.4"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"SocialiteProviders\\Crowdin\\": ""
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)