Archived
1
0
Fork 0

Merge branch '12-oauth-linkedin' into 'dev'

Resolve "OAuth - LinkedIn"

Closes #12

See merge request pnx/httpcb!17
This commit is contained in:
Henrik Hautakoski 2018-08-09 12:26:32 +00:00
commit 972e6cb4f8
11 changed files with 181 additions and 12 deletions

View file

@ -11,3 +11,4 @@
.text-github { color: @github-color; }
.text-gitlab { color: @gitlab-color; }
.text-google { color: @google-color; }
.text-linkedin { color: @linkedin-color; }

View file

@ -48,6 +48,7 @@
.button-github { .button-variant(@button-github-color, @button-github-bg); }
.button-gitlab { .button-variant(@button-gitlab-color, @button-gitlab-bg); }
.button-google { .button-variant(@button-google-color, @button-google-bg); }
.button-linkedin { .button-variant(@button-linkedin-color, @button-linkedin-bg); }
// Outline
// ----------------------------------

View file

@ -32,6 +32,7 @@
@google-color: #db4437;
@github-color: #4183c4;
@gitlab-color: #548;
@linkedin-color: #0077B5;
// ----------------------------------
// Font
@ -116,6 +117,9 @@
@button-gitlab-color: white;
@button-gitlab-bg: @gitlab-color;
@button-linkedin-color: white;
@button-linkedin-bg: @linkedin-color;
// ----------------------------------
// Shadows
// ----------------------------------

View file

@ -13,9 +13,10 @@ class League implements AdapterInterface
* @var array
*/
protected $_providerClasses = array(
'github' => '\League\OAuth2\Client\Provider\Github',
'gitlab' => '\Omines\OAuth2\Client\Provider\Gitlab',
'google' => '\League\OAuth2\Client\Provider\Google',
'github' => '\League\OAuth2\Client\Provider\Github',
'gitlab' => '\Omines\OAuth2\Client\Provider\Gitlab',
'google' => '\League\OAuth2\Client\Provider\Google',
'linkedin' => '\League\OAuth2\Client\Provider\LinkedIn',
);
/**

View file

@ -0,0 +1,63 @@
<?php
namespace Httpcb\OAuth\UserData;
class LinkedIn implements UserDataInterface
{
protected $data;
/**
* {@inheritDoc}
*/
public function __construct(array $data)
{
$this->data = $data;
}
/**
* {@inheritDoc}
*/
public function getProvider()
{
return 'LinkedIn';
}
/**
* {@inheritDoc}
*/
public function getId()
{
return $this->data['id'];
}
/**
* {@inheritDoc}
*/
public function getUsername()
{
return null;
}
/**
* {@inheritDoc}
*/
public function getName()
{
$name = '';
if (isset($this->data['firstName'])) {
$name = $this->data['firstName'];
}
if (isset($this->data['lastName'])) {
$name .= ' ' . $this->data['lastName'];
}
return $name;
}
/**
* {@inheritDoc}
*/
public function getEmail()
{
return $this->data['emailAddress'];
}
}

View file

@ -0,0 +1,17 @@
<?php
use Phinx\Migration\AbstractMigration;
class UserOauthLinkedin extends AbstractMigration
{
public function up()
{
$this->table('user')
->addColumn('linkedin_id', 'string', [
'limit' => 16,
'null' => true,
'after' => 'google_id'
])->save();
}
}

View file

@ -32,6 +32,8 @@ class User extends Model
protected $google_id;
protected $linkedin_id;
public function initialize()
{
$this->useDynamicUpdate(true);
@ -227,12 +229,31 @@ class User extends Model
return $this;
}
/**
* @return string|null
*/
public function getLinkedinId()
{
return $this->linkedin_id;
}
/**
* @param string $id
* @return User
*/
public function setLinkedinId($id)
{
$this->linkedin_id = (string) $id;
return $this;
}
public function getSocialLinks()
{
$providers = [
'github' => $this->getGithubId(),
'gitlab' => $this->getGitlabId(),
'google' => $this->getGoogleId()
'github' => $this->getGithubId(),
'gitlab' => $this->getGitlabId(),
'google' => $this->getGoogleId(),
'linkedin' => $this->getLinkedinId()
];
return array_filter($providers);

View file

@ -41,6 +41,10 @@
<a class="button button-gitlab" href="{{ url(['for': 'oauth', 'strategy': 'gitlab']) }}">
{{ icon('brand/gitlab') }} Gitlab
</a>
<a class="button button-linkedin" href="{{ url(['for': 'oauth', 'strategy': 'linkedin']) }}">
{{ icon('brand/linkedin') }} LinkedIn
</a>
</div>
</div>

View file

@ -1,8 +1,9 @@
{%
set social_links = [
'github' : [ 'connected': user.getGithubId() > 0 ],
'gitlab' : [ 'connected': user.getGitlabId() > 0, 'class': 'text-gitlab' ],
'google' : [ 'connected': user.getGoogleId() > 0, 'class': 'text-google' ]
'github' : [ 'connected': user.getGithubId() > 0 ],
'gitlab' : [ 'connected': user.getGitlabId() > 0, 'class': 'text-gitlab' ],
'google' : [ 'connected': user.getGoogleId() > 0, 'class': 'text-google' ],
'linkedin' : [ 'connected': user.getLinkedinId() | length, 'class': 'text-linkedin' ]
]
%}

View file

@ -9,6 +9,7 @@
"league/oauth2-client": "^2.3",
"league/oauth2-github": "^2.0",
"league/oauth2-google": "^2.2",
"league/oauth2-linkedin": "^4.1",
"omines/oauth2-gitlab": "^3.1",
"localheinz/json-printer": "^2.0",
"sendgrid/sendgrid": "^7.0"

61
composer.lock generated
View file

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "01d955324dab45a8647cc235d2a93d68",
"content-hash": "b2a64be9535ccaf045a7155343a64ec9",
"hash": "4c349858d6d2e69304bd4df64d883073",
"content-hash": "e1a15725333e7544dbae37ff27e14ffb",
"packages": [
{
"name": "guzzlehttp/guzzle",
@ -361,6 +361,61 @@
],
"time": "2018-03-19 17:28:55"
},
{
"name": "league/oauth2-linkedin",
"version": "4.1.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/oauth2-linkedin.git",
"reference": "0dfb338db84cb87c3d24b0205ec7f3e3a9457b81"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/oauth2-linkedin/zipball/0dfb338db84cb87c3d24b0205ec7f3e3a9457b81",
"reference": "0dfb338db84cb87c3d24b0205ec7f3e3a9457b81",
"shasum": ""
},
"require": {
"league/oauth2-client": "^2.0"
},
"require-dev": {
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"League\\OAuth2\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Steven Maguire",
"email": "stevenmaguire@gmail.com",
"homepage": "https://github.com/stevenmaguire"
}
],
"description": "LinkedIn OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
"keywords": [
"authorisation",
"authorization",
"client",
"linkedin",
"oauth",
"oauth2"
],
"time": "2018-07-23 15:43:54"
},
{
"name": "localheinz/json-printer",
"version": "2.0.0",
@ -1220,7 +1275,7 @@
"platform": {
"php": ">=7.0.0",
"ext-phalcon": ">=3.4.0",
"ext-apc": "*"
"ext-redis": "*"
},
"platform-dev": []
}