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