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
bb37b7b5
Commit
bb37b7b5
authored
Dec 25, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OpenId attribute validation and extraction updated.
parent
d21c59bc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
21 deletions
+49
-21
AuthAction.php
extensions/yii/authclient/AuthAction.php
+1
-13
OpenId.php
extensions/yii/authclient/OpenId.php
+48
-8
No files found.
extensions/yii/authclient/AuthAction.php
View file @
bb37b7b5
...
...
@@ -203,21 +203,9 @@ class AuthAction extends Action
switch
(
$_REQUEST
[
'openid_mode'
])
{
case
'id_res'
:
if
(
$client
->
validate
())
{
$attributes
=
[
'id'
=>
$client
->
getClaimedId
()
];
$rawAttributes
=
$client
->
fetchAttributes
();
foreach
(
$client
->
requiredAttributes
as
$openIdAttributeName
)
{
if
(
isset
(
$rawAttributes
[
$openIdAttributeName
]))
{
$attributes
[
$openIdAttributeName
]
=
$rawAttributes
[
$openIdAttributeName
];
}
else
{
throw
new
Exception
(
'Unable to complete the authentication because the required data was not received.'
);
}
}
$client
->
setUserAttributes
(
$attributes
);
return
$this
->
authSuccess
(
$client
);
}
else
{
throw
new
Exception
(
'Unable to complete the authentication because the required data was not received.'
);
throw
new
HttpException
(
400
,
'Unable to complete the authentication because the required data was not received.'
);
}
break
;
case
'cancel'
:
...
...
extensions/yii/authclient/OpenId.php
View file @
bb37b7b5
...
...
@@ -382,13 +382,18 @@ class OpenId extends BaseClient implements ClientInterface
}
/**
* Helper function used to scan for <meta>/<link> tags and extract information
* from them
*/
protected
function
extractHtmlTagValue
(
$content
,
$tag
,
$attrName
,
$attrValue
,
$valueName
)
* Scans content for <meta>/<link> tags and extract information from them.
* @param string $content HTML content to be be parsed.
* @param string $tag name of the source tag.
* @param string $matchAttributeName name of the source tag attribute, which should contain $matchAttributeValue
* @param string $matchAttributeValue required value of $matchAttributeName
* @param string $valueAttributeName name of the source tag attribute, which should contain searched value.
* @return string|boolean searched value, "false" on failure.
*/
protected
function
extractHtmlTagValue
(
$content
,
$tag
,
$matchAttributeName
,
$matchAttributeValue
,
$valueAttributeName
)
{
preg_match_all
(
"#<
{
$tag
}
[^>]*
$
attrName
=['
\"
].*?
$attrValue
.*?['
\"
][^>]*
$valu
eName
=['
\"
](.+?)['
\"
][^>]*/?>#i"
,
$content
,
$matches1
);
preg_match_all
(
"#<
{
$tag
}
[^>]*
$value
Name
=['
\"
](.+?)['
\"
][^>]*
$attrName
=['
\"
].*?
$attr
Value
.*?['
\"
][^>]*/?>#i"
,
$content
,
$matches2
);
preg_match_all
(
"#<
{
$tag
}
[^>]*
$
matchAttributeName
=['
\"
].*?
$matchAttributeValue
.*?['
\"
][^>]*
$valueAttribut
eName
=['
\"
](.+?)['
\"
][^>]*/?>#i"
,
$content
,
$matches1
);
preg_match_all
(
"#<
{
$tag
}
[^>]*
$value
AttributeName
=['
\"
](.+?)['
\"
][^>]*
$matchAttributeName
=['
\"
].*?
$matchAttribute
Value
.*?['
\"
][^>]*/?>#i"
,
$content
,
$matches2
);
$result
=
array_merge
(
$matches1
[
1
],
$matches2
[
1
]);
return
empty
(
$result
)
?
false
:
$result
[
0
];
}
...
...
@@ -728,9 +733,10 @@ class OpenId extends BaseClient implements ClientInterface
/**
* Performs OpenID verification with the OP.
* @param boolean $validateRequiredAttributes whether to validate required attributes.
* @return boolean whether the verification was successful.
*/
public
function
validate
()
public
function
validate
(
$validateRequiredAttributes
=
true
)
{
$claimedId
=
$this
->
getClaimedId
();
if
(
empty
(
$claimedId
))
{
...
...
@@ -769,7 +775,32 @@ class OpenId extends BaseClient implements ClientInterface
$response
=
$this
->
sendRequest
(
$serverInfo
[
'url'
],
'POST'
,
$params
);
return
preg_match
(
'/is_valid\s*:\s*true/i'
,
$response
);
if
(
preg_match
(
'/is_valid\s*:\s*true/i'
,
$response
))
{
if
(
$validateRequiredAttributes
)
{
return
$this
->
validateRequiredAttributes
();
}
else
{
return
true
;
}
}
else
{
return
false
;
}
}
/**
* Checks if all required attributes are present in the server response.
* @return boolean whether all required attributes are present.
*/
protected
function
validateRequiredAttributes
()
{
if
(
!
empty
(
$this
->
requiredAttributes
))
{
$attributes
=
$this
->
fetchAttributes
();
foreach
(
$this
->
requiredAttributes
as
$openIdAttributeName
)
{
if
(
!
isset
(
$attributes
[
$openIdAttributeName
]))
{
return
false
;
}
}
}
return
true
;
}
/**
...
...
@@ -856,4 +887,12 @@ class OpenId extends BaseClient implements ClientInterface
}
return
$this
->
fetchSregAttributes
();
}
/**
* @inheritdoc
*/
protected
function
initUserAttributes
()
{
return
array_merge
([
'id'
=>
$this
->
getClaimedId
()],
$this
->
fetchAttributes
());
}
}
\ 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