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
c8a0591f
Commit
c8a0591f
authored
Dec 16, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
"yii\authclient\AuthAction" fixed.
"yii\authclient\ClientInterface" applied.
parent
776a9250
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
29 deletions
+31
-29
AuthAction.php
extensions/yii/authclient/AuthAction.php
+25
-27
BaseOAuth.php
extensions/yii/authclient/BaseOAuth.php
+3
-1
OpenId.php
extensions/yii/authclient/OpenId.php
+3
-1
No files found.
extensions/yii/authclient/AuthAction.php
View file @
c8a0591f
...
...
@@ -23,15 +23,13 @@ use Yii;
class
AuthAction
extends
Action
{
/**
* @var string name of the auth provider collection application component.
* This component will be used to fetch {@link services} value if it is not set.
* @var string name of the auth client collection application component.
*/
public
$
provider
Collection
;
public
$
client
Collection
;
/**
* @var string name of the GET param , which should be used to passed auth provider id to URL
* defined by {@link baseAuthUrl}.
* @var string name of the GET param, which is used to passed auth client id to this action.
*/
public
$
providerIdGetParamName
=
'provider
'
;
public
$
clientIdGetParamName
=
'client_id
'
;
/**
* @var callable PHP callback, which should be triggered in case of successful authentication.
*/
...
...
@@ -106,15 +104,15 @@ class AuthAction extends Action
*/
public
function
run
()
{
if
(
!
empty
(
$_GET
[
$this
->
provider
IdGetParamName
]))
{
$
providerId
=
$_GET
[
$this
->
provider
IdGetParamName
];
/** @var \yii\authclient\
provider\Collection $providerC
ollection */
$
providerCollection
=
Yii
::
$app
->
getComponent
(
$this
->
provider
Collection
);
if
(
!
$
providerCollection
->
hasProvider
(
$provider
Id
))
{
throw
new
NotFoundHttpException
(
"Unknown auth
provider '
{
$provider
Id
}
'"
);
}
$
provider
=
$providerCollection
->
getProvider
(
$provider
Id
);
return
$this
->
auth
enticate
(
$provider
);
if
(
!
empty
(
$_GET
[
$this
->
client
IdGetParamName
]))
{
$
clientId
=
$_GET
[
$this
->
client
IdGetParamName
];
/** @var \yii\authclient\
Collection $c
ollection */
$
collection
=
Yii
::
$app
->
getComponent
(
$this
->
client
Collection
);
if
(
!
$
collection
->
hasClient
(
$client
Id
))
{
throw
new
NotFoundHttpException
(
"Unknown auth
client '
{
$client
Id
}
'"
);
}
$
client
=
$collection
->
getClient
(
$client
Id
);
return
$this
->
auth
(
$client
);
}
else
{
throw
new
NotFoundHttpException
();
}
...
...
@@ -124,14 +122,14 @@ class AuthAction extends Action
* @param mixed $provider
* @throws \yii\base\NotSupportedException
*/
protected
function
auth
enticate
(
$provider
)
protected
function
auth
(
$provider
)
{
if
(
$provider
instanceof
OpenId
)
{
return
$this
->
auth
enticate
OpenId
(
$provider
);
return
$this
->
authOpenId
(
$provider
);
}
elseif
(
$provider
instanceof
OAuth2
)
{
return
$this
->
auth
enticate
OAuth2
(
$provider
);
return
$this
->
authOAuth2
(
$provider
);
}
elseif
(
$provider
instanceof
OAuth1
)
{
return
$this
->
auth
enticate
OAuth1
(
$provider
);
return
$this
->
authOAuth1
(
$provider
);
}
else
{
throw
new
NotSupportedException
(
'Provider "'
.
get_class
(
$provider
)
.
'" is not supported.'
);
}
...
...
@@ -141,7 +139,7 @@ class AuthAction extends Action
* @param mixed $provider
* @return \yii\web\Response
*/
protected
function
auth
enticate
Success
(
$provider
)
protected
function
authSuccess
(
$provider
)
{
call_user_func
(
$this
->
successCallback
,
$provider
);
return
$this
->
redirectSuccess
();
...
...
@@ -198,7 +196,7 @@ class AuthAction extends Action
* @throws Exception on failure
* @throws \yii\web\HttpException
*/
protected
function
auth
enticate
OpenId
(
$provider
)
protected
function
authOpenId
(
$provider
)
{
if
(
!
empty
(
$_REQUEST
[
'openid_mode'
]))
{
switch
(
$_REQUEST
[
'openid_mode'
])
{
...
...
@@ -215,8 +213,8 @@ class AuthAction extends Action
throw
new
Exception
(
'Unable to complete the authentication because the required data was not received.'
);
}
}
$provider
->
setAttributes
(
$attributes
);
return
$this
->
auth
enticate
Success
(
$provider
);
$provider
->
set
User
Attributes
(
$attributes
);
return
$this
->
authSuccess
(
$provider
);
}
else
{
throw
new
Exception
(
'Unable to complete the authentication because the required data was not received.'
);
}
...
...
@@ -244,7 +242,7 @@ class AuthAction extends Action
* @param OAuth1 $provider
* @return \yii\web\Response
*/
protected
function
auth
enticate
OAuth1
(
$provider
)
protected
function
authOAuth1
(
$provider
)
{
// user denied error
if
(
isset
(
$_GET
[
'denied'
]))
{
...
...
@@ -265,7 +263,7 @@ class AuthAction extends Action
}
else
{
// Upgrade to access token.
$accessToken
=
$provider
->
fetchAccessToken
();
return
$this
->
auth
enticate
Success
(
$provider
);
return
$this
->
authSuccess
(
$provider
);
}
}
...
...
@@ -274,7 +272,7 @@ class AuthAction extends Action
* @return \yii\web\Response
* @throws \yii\base\Exception
*/
protected
function
auth
enticate
OAuth2
(
$provider
)
protected
function
authOAuth2
(
$provider
)
{
if
(
isset
(
$_GET
[
'error'
]))
{
if
(
$_GET
[
'error'
]
==
'access_denied'
)
{
...
...
@@ -298,7 +296,7 @@ class AuthAction extends Action
$code
=
$_GET
[
'code'
];
$token
=
$provider
->
fetchAccessToken
(
$code
);
if
(
!
empty
(
$token
))
{
return
$this
->
auth
enticate
Success
(
$provider
);
return
$this
->
authSuccess
(
$provider
);
}
else
{
return
$this
->
redirectCancel
();
}
...
...
extensions/yii/authclient/BaseOAuth.php
View file @
c8a0591f
...
...
@@ -21,8 +21,10 @@ use yii\helpers\Json;
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
abstract
class
BaseOAuth
extends
Component
abstract
class
BaseOAuth
extends
Component
implements
ClientInterface
{
use
ClientTrait
;
const
CONTENT_TYPE_JSON
=
'json'
;
// JSON format
const
CONTENT_TYPE_URLENCODED
=
'urlencoded'
;
// urlencoded query string, like name1=value1&name2=value2
const
CONTENT_TYPE_XML
=
'xml'
;
// XML format
...
...
extensions/yii/authclient/OpenId.php
View file @
c8a0591f
...
...
@@ -25,8 +25,10 @@ use yii\base\NotSupportedException;
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
OpenId
extends
Component
class
OpenId
extends
Component
implements
ClientInterface
{
use
ClientTrait
;
/**
* @var array list of attributes, which should be requested from server.
*/
...
...
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