Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Added LinkedIn OpenID Support #286

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"require": {
"php": "^8.1",
"laravel/jetstream": "^3.0|^4.0",
"laravel/socialite": "^5.8.1"
"laravel/socialite": "^5.9"
},
"require-dev": {
"inertiajs/inertia-laravel": "^0.6.4",
Expand Down
20 changes: 20 additions & 0 deletions src/Providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public static function hasLinkedInSupport(): bool
return static::enabled(static::linkedin());
}

/**
* Determine if the application has support for the LinkedIn OpenID provider.
*/
public static function hasLinkedInOpenIdSupport(): bool
{
return static::enabled(static::linkedinOpenId());
}

/**
* Determine if the application has support for the Slack provider.
*/
Expand All @@ -73,6 +81,8 @@ public static function hasSlackSupport(): bool

/**
* Determine if the application has support for the Twitter provider.
*
* @deprecated use `hasTwitterOAuth1Support` instead
*/
public static function hasTwitterSupport(): bool
{
Expand Down Expand Up @@ -144,6 +154,14 @@ public static function linkedin(): string
return 'linkedin';
}

/**
* Enable the LinkedIn OpenID provider.
*/
public static function linkedinOpenId(): string
{
return 'linkedin-openid';
}

/**
* Enable the Slack provider.
*/
Expand All @@ -154,6 +172,8 @@ public static function slack(): string

/**
* Enable the Twitter provider.
*
* @deprecated use `twitterOAuth1` instead.
*/
public static function twitter(): string
{
Expand Down
25 changes: 25 additions & 0 deletions src/Resolvers/OAuth/LinkedInOpenIdOauth2RefreshResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace JoelButcher\Socialstream\Resolvers\OAuth;

use JoelButcher\Socialstream\Concerns\RefreshesOauth2Tokens;
use JoelButcher\Socialstream\Contracts\Oauth2RefreshResolver;
use Laravel\Socialite\Two\LinkedInOpenIdProvider;

class LinkedInOpenIdOauth2RefreshResolver extends LinkedInOpenIdProvider implements Oauth2RefreshResolver
{
use RefreshesOauth2Tokens;

/**
* Create a new provider instance.
*/
public function __construct()
{
parent::__construct(
request: request(),
clientId: config('services.linkedin.client_id'),
clientSecret: config('services.linkedin.client_secret'),
redirectUrl: '',
);
}
}
8 changes: 8 additions & 0 deletions src/Socialstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ public static function hasLinkedInSupport(): bool
return Providers::hasLinkedInSupport();
}

/**
* Determine if the application has support for the LinkedIn OpenID provider.
*/
public static function hasLinkedInOpenIdSupport(): bool
{
return Providers::hasLinkedInOpenIdSupport();
}

/**
* Determine if the application has support for the Slack provider.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/SocialstreamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ protected function configureRefreshTokenResolvers(): void
Socialstream::refreshesTokensForProviderUsing(Providers::gitlab(), GitlabOauth2RefreshResolver::class);
Socialstream::refreshesTokensForProviderUsing(Providers::google(), GoogleOauth2RefreshResolver::class);
Socialstream::refreshesTokensForProviderUsing(Providers::linkedin(), LinkedInOauth2RefreshResolver::class);
Socialstream::refreshesTokensForProviderUsing(Providers::linkedinOpenId(), LinkedInOauth2RefreshResolver::class);
Socialstream::refreshesTokensForProviderUsing(Providers::slack(), SlackOauth2RefreshResolver::class);
Socialstream::refreshesTokensForProviderUsing(Providers::twitter(), TwitterOauth2RefreshResolver::class);
Socialstream::refreshesTokensForProviderUsing(Providers::twitterOAuth1(), TwitterOauth2RefreshResolver::class);
Socialstream::refreshesTokensForProviderUsing(Providers::twitterOAuth2(), TwitterOauth2RefreshResolver::class);
}

/**
Expand Down
17 changes: 15 additions & 2 deletions stubs/inertia/resources/js/Components/ConnectedAccount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ defineProps({
default: null,
}
});

const providerName = computed(() => {
switch(this.provider) {
case 'twitter':
case 'twitter-oauth-2':
return 'Twitter'
case 'linkedin':
case 'linkedin-openid':
return 'LinkedIn'
default:
return name.charAt(0).toUpperCase() + provider.slice(1);
};
});
</script>

<template>
Expand All @@ -27,13 +40,13 @@ defineProps({
<GithubIcon class="h-6 w-6 mr-2" v-if="provider === 'github'" />
<GitLabIcon class="h-6 w-6 mr-2" v-if="provider === 'gitlab'" />
<GoogleIcon class="h-6 w-6 mr-2" v-if="provider === 'google'" />
<LinkedInIcon class="h-6 w-6 mr-2" v-if="provider === 'linkedin'" />
<LinkedInIcon class="h-6 w-6 mr-2" v-if="['linkedin', 'linkedin-openid'].includes(provider)" />
<SlackIcon class="h-6 w-6 mr-2" v-if="provider === 'slack'" />
<TwitterIcon class="h-6 w-6 mr-2" v-if="['twitter', 'twitter-oauth-2'].includes(provider)" />

<div>
<div class="text-sm font-semibold text-gray-600 dark:text-gray-400">
{{ provider === 'twitter-oauth-2' ? 'Twitter' : provider.charAt(0).toUpperCase() + provider.slice(1) }}
{{ providerName }}
</div>

<div v-if="createdAt !== null" class="text-xs text-gray-500">
Expand Down
5 changes: 5 additions & 0 deletions stubs/inertia/resources/js/Components/Socialstream.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const error = computed(() => usePage().props.errors.socialstream);
<span class="sr-only">LinkedIn</span>
</a>

<a v-if="$page.props.socialstream.providers.includes('linkedin-openid')" :href="route('oauth.redirect', 'linkedin-openid')">
<LinkedInIcon class="h-6 w-6 mx-2"/>
<span class="sr-only">LinkedIn</span>
</a>

<a v-if="$page.props.socialstream.providers.includes('slack')" :href="route('oauth.redirect', 'slack')">
<SlackIcon class="h-6 w-6 mx-2"/>
<span class="sr-only">Slack</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<x-socialstream-icons.twitter class="h-6 w-6 mr-2" />
@break
@case(JoelButcher\Socialstream\Providers::linkedin())
@case(JoelButcher\Socialstream\Providers::linkedinOpenId())
<x-socialstream-icons.linkedin class="h-6 w-6 mr-2" />
@break
@case(JoelButcher\Socialstream\Providers::github())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
</a>
@endif

@if (JoelButcher\Socialstream\Socialstream::hasLinkedInOpenIdSupport())
<a href="{{ route('oauth.redirect', ['provider' => JoelButcher\Socialstream\Providers::linkedinOpenId()]) }}">
<x-socialstream-icons.linkedin class="h-6 w-6 mx-2" />
<span class="sr-only">LinkedIn</span>
</a>
@endif

@if (JoelButcher\Socialstream\Socialstream::hasSlackSupport())
<a href="{{ route('oauth.redirect', ['provider' => JoelButcher\Socialstream\Providers::slack()]) }}">
<x-socialstream-icons.slack class="h-6 w-6 mx-2" />
Expand Down
11 changes: 7 additions & 4 deletions stubs/pest-tests/SocialstreamRegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@
$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
})->with([
[Providers::google()],
[Providers::facebook()],
[Providers::linkedin()],
[Providers::bitbucket()],
[Providers::facebook()],
[Providers::github()],
[Providers::gitlab()],
[Providers::twitter()],
[Providers::google()],
[Providers::linkedin()],
[Providers::linkedinOpenId()],
[Providers::slack()],
[Providers::twitterOAuth1()],
[Providers::twitterOAuth2()],
]);
11 changes: 7 additions & 4 deletions stubs/tests/SocialstreamRegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ public function test_users_can_register_using_socialite_providers(string $social
public static function socialiteProvidersDataProvider(): array
{
return [
[Providers::google()],
[Providers::facebook()],
[Providers::linkedin()],
[Providers::bitbucket()],
[Providers::facebook()],
[Providers::github()],
[Providers::gitlab()],
[Providers::twitter()],
[Providers::google()],
[Providers::linkedin()],
[Providers::linkedinOpenId()],
[Providers::slack()],
[Providers::twitterOAuth1()],
[Providers::twitterOAuth2()],
];
}
}
6 changes: 6 additions & 0 deletions tests/Unit/ProvidersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
$this->assertTrue(Providers::hasLinkedInSupport());
});

it('supports the \'linked-openid\' in_provider', function (): void {
Config::set('socialstream.providers', [Providers::linkedinOpenId()]);

$this->assertTrue(Providers::hasLinkedInOpenIdSupport());
});

it('supports the \'twitter\' provider', function (): void {
Config::set('socialstream.providers', [Providers::twitter()]);

Expand Down