Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
b1f6354f
Commit
b1f6354f
authored
Dec 25, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auth clients for Facebook, GitHub, LinkedIn added.
parent
124f4fa9
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
372 additions
and
4 deletions
+372
-4
Facebook.php
extensions/yii/authclient/clients/Facebook.php
+49
-0
GitHub.php
extensions/yii/authclient/clients/GitHub.php
+59
-0
GoogleOAuth.php
extensions/yii/authclient/clients/GoogleOAuth.php
+19
-2
GoogleOpenId.php
extensions/yii/authclient/clients/GoogleOpenId.php
+19
-1
LinkedIn.php
extensions/yii/authclient/clients/LinkedIn.php
+134
-0
YandexOAuth.php
extensions/yii/authclient/clients/YandexOAuth.php
+73
-0
YandexOpenId.php
extensions/yii/authclient/clients/YandexOpenId.php
+19
-1
No files found.
extensions/yii/authclient/clients/Facebook.php
0 → 100644
View file @
b1f6354f
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\authclient\clients
;
use
yii\authclient\OAuth2
;
/**
* Facebook allows authentication via Facebook OAuth.
* In order to use Facebook OAuth you must register your application at [[https://developers.facebook.com/apps]].
*
* @see https://developers.facebook.com/apps
* @see http://developers.facebook.com/docs/reference/api
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
Facebook
extends
OAuth2
{
/**
* @inheritdoc
*/
public
$authUrl
=
'https://www.facebook.com/dialog/oauth'
;
/**
* @inheritdoc
*/
public
$tokenUrl
=
'https://graph.facebook.com/oauth/access_token'
;
/**
* @inheritdoc
*/
public
$apiBaseUrl
=
'https://graph.facebook.com'
;
/**
* @inheritdoc
*/
public
$scope
=
'email'
;
/**
* @inheritdoc
*/
protected
function
initUserAttributes
()
{
return
$this
->
api
(
'me'
,
'GET'
);
}
}
\ No newline at end of file
extensions/yii/authclient/clients/GitHub.php
0 → 100644
View file @
b1f6354f
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\authclient\clients
;
use
yii\authclient\OAuth2
;
/**
* GitHub allows authentication via GitHub OAuth.
* In order to use GitHub OAuth you must register your application at [[https://github.com/settings/applications/new]].
*
* @see http://developer.github.com/v3/oauth/
* @see https://github.com/settings/applications/new
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
GitHub
extends
OAuth2
{
/**
* @inheritdoc
*/
public
$authUrl
=
'https://github.com/login/oauth/authorize'
;
/**
* @inheritdoc
*/
public
$tokenUrl
=
'https://github.com/login/oauth/access_token'
;
/**
* @inheritdoc
*/
public
$apiBaseUrl
=
'https://api.github.com'
;
/**
* @inheritdoc
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
scope
===
null
)
{
$this
->
scope
=
implode
(
' '
,
[
'user'
,
'user:email'
,
]);
}
}
/**
* @inheritdoc
*/
protected
function
initUserAttributes
()
{
return
$this
->
api
(
'user'
,
'GET'
);
}
}
\ No newline at end of file
extensions/yii/authclient/clients/GoogleOAuth.php
View file @
b1f6354f
...
...
@@ -39,6 +39,7 @@ class GoogleOAuth extends OAuth2
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
scope
===
null
)
{
$this
->
scope
=
implode
(
' '
,
[
'https://www.googleapis.com/auth/userinfo.profile'
,
...
...
@@ -52,7 +53,22 @@ class GoogleOAuth extends OAuth2
*/
protected
function
initUserAttributes
()
{
$attributes
=
$this
->
api
(
'userinfo'
,
'GET'
);
return
$attributes
;
return
$this
->
api
(
'userinfo'
,
'GET'
);
}
/**
* @inheritdoc
*/
protected
function
defaultName
()
{
return
'google'
;
}
/**
* @inheritdoc
*/
protected
function
defaultTitle
()
{
return
'Google'
;
}
}
\ No newline at end of file
extensions/yii/authclient/clients/GoogleOpenId.php
View file @
b1f6354f
...
...
@@ -10,7 +10,8 @@ namespace yii\authclient\clients;
use
yii\authclient\OpenId
;
/**
* Class GoogleOpenId
* GoogleOpenId allows authentication via Google OpenId.
* Unlike Google OAuth you do not need to register your application anywhere in order to use Google OpenId.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
...
...
@@ -54,4 +55,20 @@ class GoogleOpenId extends OpenId
'popupHeight'
=>
520
,
];
}
/**
* @inheritdoc
*/
protected
function
defaultName
()
{
return
'google'
;
}
/**
* @inheritdoc
*/
protected
function
defaultTitle
()
{
return
'Google'
;
}
}
\ No newline at end of file
extensions/yii/authclient/clients/LinkedIn.php
0 → 100644
View file @
b1f6354f
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\authclient\clients
;
use
yii\authclient\OAuth2
;
use
yii\web\HttpException
;
use
Yii
;
/**
* LinkedIn allows authentication via LinkedIn OAuth.
* In order to use linkedIn OAuth you must register your application at [[https://www.linkedin.com/secure/developer]].
*
* @see http://developer.linkedin.com/documents/authentication
* @see https://www.linkedin.com/secure/developer
* @see http://developer.linkedin.com/apis
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
LinkedIn
extends
OAuth2
{
/**
* @inheritdoc
*/
public
$authUrl
=
'https://www.linkedin.com/uas/oauth2/authorization'
;
/**
* @inheritdoc
*/
public
$tokenUrl
=
'https://www.linkedin.com/uas/oauth2/accessToken'
;
/**
* @inheritdoc
*/
public
$apiBaseUrl
=
'https://api.linkedin.com/v1'
;
/**
* @inheritdoc
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
scope
===
null
)
{
$this
->
scope
=
implode
(
' '
,
[
'r_basicprofile'
,
'r_emailaddress'
,
]);
}
}
/**
* @inheritdoc
*/
protected
function
defaultNormalizeUserAttributeMap
()
{
return
[
'email'
=>
'email-address'
,
'first_name'
=>
'first-name'
,
'last_name'
=>
'last-name'
,
];
}
/**
* @inheritdoc
*/
protected
function
initUserAttributes
()
{
$attributeNames
=
[
'id'
,
'email-address'
,
'first-name'
,
'last-name'
,
'public-profile-url'
,
];
return
$this
->
api
(
'people/~:('
.
implode
(
','
,
$attributeNames
)
.
')'
,
'GET'
);
}
/**
* @inheritdoc
*/
public
function
buildAuthUrl
(
array
$params
=
[])
{
$authState
=
$this
->
generateAuthState
();
$this
->
setState
(
'authState'
,
$authState
);
$params
[
'state'
]
=
$authState
;
return
parent
::
buildAuthUrl
(
$params
);
}
/**
* @inheritdoc
*/
public
function
fetchAccessToken
(
$authCode
,
array
$params
=
[])
{
$authState
=
$this
->
getState
(
'authState'
);
if
(
!
isset
(
$_REQUEST
[
'state'
])
||
empty
(
$authState
)
||
strcmp
(
$_REQUEST
[
'state'
],
$authState
)
!==
0
)
{
throw
new
HttpException
(
400
,
'Invalid auth state parameter.'
);
}
else
{
$this
->
removeState
(
'authState'
);
}
return
parent
::
fetchAccessToken
(
$authCode
,
$params
);
}
/**
* @inheritdoc
*/
protected
function
apiInternal
(
$accessToken
,
$url
,
$method
,
array
$params
)
{
$params
[
'oauth2_access_token'
]
=
$accessToken
->
getToken
();
return
$this
->
sendRequest
(
$method
,
$url
,
$params
);
}
/**
* @inheritdoc
*/
protected
function
defaultReturnUrl
()
{
$params
=
$_GET
;
unset
(
$params
[
'code'
]);
unset
(
$params
[
'state'
]);
return
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
Yii
::
$app
->
controller
->
getRoute
(),
$params
);
}
/**
* Generates the auth state value.
* @return string auth state value.
*/
protected
function
generateAuthState
()
{
return
sha1
(
uniqid
(
get_class
(
$this
),
true
));
}
}
\ No newline at end of file
extensions/yii/authclient/clients/YandexOAuth.php
0 → 100644
View file @
b1f6354f
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\authclient\clients
;
use
yii\authclient\OAuth2
;
/**
* YandexOAuth allows authentication via Yandex OAuth.
* In order to use Yandex OAuth you must register your application at [[https://oauth.yandex.ru/client/new]].
*
* @see https://oauth.yandex.ru/client/new
* @see http://api.yandex.ru/login/doc/dg/reference/response.xml
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
YandexOAuth
extends
OAuth2
{
/**
* @inheritdoc
*/
public
$authUrl
=
'https://oauth.yandex.ru/authorize'
;
/**
* @inheritdoc
*/
public
$tokenUrl
=
'https://oauth.yandex.ru/token'
;
/**
* @inheritdoc
*/
public
$apiBaseUrl
=
'https://login.yandex.ru'
;
/**
* @inheritdoc
*/
protected
function
initUserAttributes
()
{
return
$this
->
api
(
'info'
,
'GET'
);
}
/**
* @inheritdoc
*/
protected
function
apiInternal
(
$accessToken
,
$url
,
$method
,
array
$params
)
{
if
(
!
isset
(
$params
[
'format'
]))
{
$params
[
'format'
]
=
'json'
;
}
$params
[
'oauth_token'
]
=
$accessToken
->
getToken
();
return
$this
->
sendRequest
(
$method
,
$url
,
$params
);
}
/**
* @inheritdoc
*/
protected
function
defaultName
()
{
return
'yandex'
;
}
/**
* @inheritdoc
*/
protected
function
defaultTitle
()
{
return
'Yandex'
;
}
}
\ No newline at end of file
extensions/yii/authclient/clients/YandexOpenId.php
View file @
b1f6354f
...
...
@@ -10,7 +10,8 @@ namespace yii\authclient\clients;
use
yii\authclient\OpenId
;
/**
* Class YandexOpenId
* YandexOpenId allows authentication via Yandex OpenId.
* Unlike Yandex OAuth you do not need to register your application anywhere in order to use Yandex OpenId.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
...
...
@@ -50,4 +51,20 @@ class YandexOpenId extends OpenId
'popupHeight'
=>
550
,
];
}
/**
* @inheritdoc
*/
protected
function
defaultName
()
{
return
'yandex'
;
}
/**
* @inheritdoc
*/
protected
function
defaultTitle
()
{
return
'Yandex'
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment