Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
a6d1a875
Unverified
Commit
a6d1a875
authored
6 years ago
by
Tim van Dijen
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #904 from simplesamlphp/scrutinizer-patch-1
Scrutinizer Auto-Fixes
parents
d66f956f
fb49e717
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/authfacebook/lib/Auth/Source/Facebook.php
+115
-115
115 additions, 115 deletions
modules/authfacebook/lib/Auth/Source/Facebook.php
with
115 additions
and
115 deletions
modules/authfacebook/lib/Auth/Source/Facebook.php
+
115
−
115
View file @
a6d1a875
...
@@ -13,137 +13,137 @@ use SimpleSAML\Module;
...
@@ -13,137 +13,137 @@ use SimpleSAML\Module;
class
Facebook
extends
\SimpleSAML\Auth\Source
class
Facebook
extends
\SimpleSAML\Auth\Source
{
{
/**
/**
* The string used to identify our states.
* The string used to identify our states.
*/
*/
const
STAGE_INIT
=
'facebook:init'
;
const
STAGE_INIT
=
'facebook:init'
;
/**
/**
* The key of the AuthId field in the state.
* The key of the AuthId field in the state.
*/
*/
const
AUTHID
=
'facebook:AuthId'
;
const
AUTHID
=
'facebook:AuthId'
;
/**
/**
* Facebook App ID or API Key
* Facebook App ID or API Key
*/
*/
private
$api_key
;
private
$api_key
;
/**
/**
* Facebook App Secret
* Facebook App Secret
*/
*/
private
$secret
;
private
$secret
;
/**
/**
* Which additional data permissions to request from user
* Which additional data permissions to request from user
*/
*/
private
$req_perms
;
private
$req_perms
;
/**
/**
* A comma-separated list of user profile fields to request.
* A comma-separated list of user profile fields to request.
*
*
* Note that some user fields require appropriate permissions. For
* Note that some user fields require appropriate permissions. For
* example, to retrieve the user's primary email address, "email" must
* example, to retrieve the user's primary email address, "email" must
* be specified in both the req_perms and the user_fields parameter.
* be specified in both the req_perms and the user_fields parameter.
*
*
* When empty, only the app-specific user id and name will be returned.
* When empty, only the app-specific user id and name will be returned.
*
*
* See the Graph API specification for all available user fields:
* See the Graph API specification for all available user fields:
* https://developers.facebook.com/docs/graph-api/reference/v2.6/user
* https://developers.facebook.com/docs/graph-api/reference/v2.6/user
*/
*/
private
$user_fields
;
private
$user_fields
;
/**
/**
* Constructor for this authentication source.
* Constructor for this authentication source.
*
*
* @param array $info Information about this authentication source.
* @param array $info Information about this authentication source.
* @param array $config Configuration.
* @param array $config Configuration.
*/
*/
public
function
__construct
(
$info
,
$config
)
public
function
__construct
(
$info
,
$config
)
{
{
assert
(
is_array
(
$info
));
assert
(
is_array
(
$info
));
assert
(
is_array
(
$config
));
assert
(
is_array
(
$config
));
// Call the parent constructor first, as required by the interface
// Call the parent constructor first, as required by the interface
parent
::
__construct
(
$info
,
$config
);
parent
::
__construct
(
$info
,
$config
);
$cfgParse
=
\SimpleSAML\Configuration
::
loadFromArray
(
$config
,
'authsources['
.
var_export
(
$this
->
authId
,
true
)
.
']'
);
$cfgParse
=
\SimpleSAML\Configuration
::
loadFromArray
(
$config
,
'authsources['
.
var_export
(
$this
->
authId
,
true
)
.
']'
);
$this
->
api_key
=
$cfgParse
->
getString
(
'api_key'
);
$this
->
api_key
=
$cfgParse
->
getString
(
'api_key'
);
$this
->
secret
=
$cfgParse
->
getString
(
'secret'
);
$this
->
secret
=
$cfgParse
->
getString
(
'secret'
);
$this
->
req_perms
=
$cfgParse
->
getString
(
'req_perms'
,
NULL
);
$this
->
req_perms
=
$cfgParse
->
getString
(
'req_perms'
,
NULL
);
$this
->
user_fields
=
$cfgParse
->
getString
(
'user_fields'
,
NULL
);
$this
->
user_fields
=
$cfgParse
->
getString
(
'user_fields'
,
NULL
);
}
}
/**
/**
* Log-in using Facebook platform
* Log-in using Facebook platform
*
*
* @param array &$state Information about the current authentication.
* @param array &$state Information about the current authentication.
*/
*/
public
function
authenticate
(
&
$state
)
public
function
authenticate
(
&
$state
)
{
{
assert
(
is_array
(
$state
));
assert
(
is_array
(
$state
));
// We are going to need the authId in order to retrieve this authentication source later
// We are going to need the authId in order to retrieve this authentication source later
$state
[
self
::
AUTHID
]
=
$this
->
authId
;
$state
[
self
::
AUTHID
]
=
$this
->
authId
;
\SimpleSAML\Auth\State
::
saveState
(
$state
,
self
::
STAGE_INIT
);
\SimpleSAML\Auth\State
::
saveState
(
$state
,
self
::
STAGE_INIT
);
$facebook
=
new
Module\authfacebook\Facebook
(
array
(
'appId'
=>
$this
->
api_key
,
'secret'
=>
$this
->
secret
),
$state
);
$facebook
=
new
Module\authfacebook\Facebook
(
array
(
'appId'
=>
$this
->
api_key
,
'secret'
=>
$this
->
secret
),
$state
);
$facebook
->
destroySession
();
$facebook
->
destroySession
();
$linkback
=
Module
::
getModuleURL
(
'authfacebook/linkback.php'
);
$linkback
=
Module
::
getModuleURL
(
'authfacebook/linkback.php'
);
$url
=
$facebook
->
getLoginUrl
(
array
(
'redirect_uri'
=>
$linkback
,
'scope'
=>
$this
->
req_perms
));
$url
=
$facebook
->
getLoginUrl
(
array
(
'redirect_uri'
=>
$linkback
,
'scope'
=>
$this
->
req_perms
));
\SimpleSAML\Auth\State
::
saveState
(
$state
,
self
::
STAGE_INIT
);
\SimpleSAML\Auth\State
::
saveState
(
$state
,
self
::
STAGE_INIT
);
\SimpleSAML\Utils\HTTP
::
redirectTrustedURL
(
$url
);
\SimpleSAML\Utils\HTTP
::
redirectTrustedURL
(
$url
);
}
}
public
function
finalStep
(
&
$state
)
public
function
finalStep
(
&
$state
)
{
{
assert
(
is_array
(
$state
));
assert
(
is_array
(
$state
));
$facebook
=
new
Module\authfacebook\Facebook
(
array
(
'appId'
=>
$this
->
api_key
,
'secret'
=>
$this
->
secret
),
$state
);
$facebook
=
new
Module\authfacebook\Facebook
(
array
(
'appId'
=>
$this
->
api_key
,
'secret'
=>
$this
->
secret
),
$state
);
$uid
=
$facebook
->
getUser
();
$uid
=
$facebook
->
getUser
();
if
(
isset
(
$uid
)
&&
$uid
)
{
if
(
isset
(
$uid
)
&&
$uid
)
{
try
{
try
{
$info
=
$facebook
->
api
(
"/"
.
$uid
.
(
$this
->
user_fields
?
"?fields="
.
$this
->
user_fields
:
""
));
$info
=
$facebook
->
api
(
"/"
.
$uid
.
(
$this
->
user_fields
?
"?fields="
.
$this
->
user_fields
:
""
));
}
catch
(
\FacebookApiException
$e
)
{
}
catch
(
\FacebookApiException
$e
)
{
throw
new
\SimpleSAML\Error\AuthSource
(
$this
->
authId
,
'Error getting user profile.'
,
$e
);
throw
new
\SimpleSAML\Error\AuthSource
(
$this
->
authId
,
'Error getting user profile.'
,
$e
);
}
}
}
}
if
(
!
isset
(
$info
))
{
if
(
!
isset
(
$info
))
{
throw
new
\SimpleSAML\Error\AuthSource
(
$this
->
authId
,
'Error getting user profile.'
);
throw
new
\SimpleSAML\Error\AuthSource
(
$this
->
authId
,
'Error getting user profile.'
);
}
}
$attributes
=
array
();
$attributes
=
array
();
foreach
(
$info
as
$key
=>
$value
)
{
foreach
(
$info
as
$key
=>
$value
)
{
if
(
is_string
(
$value
)
&&
!
empty
(
$value
))
{
if
(
is_string
(
$value
)
&&
!
empty
(
$value
))
{
$attributes
[
'facebook.'
.
$key
]
=
array
((
string
)
$value
);
$attributes
[
'facebook.'
.
$key
]
=
array
((
string
)
$value
);
}
}
}
}
if
(
array_key_exists
(
'third_party_id'
,
$info
))
{
if
(
array_key_exists
(
'third_party_id'
,
$info
))
{
$attributes
[
'facebook_user'
]
=
array
(
$info
[
'third_party_id'
]
.
'@facebook.com'
);
$attributes
[
'facebook_user'
]
=
array
(
$info
[
'third_party_id'
]
.
'@facebook.com'
);
}
else
{
}
else
{
$attributes
[
'facebook_user'
]
=
array
(
$uid
.
'@facebook.com'
);
$attributes
[
'facebook_user'
]
=
array
(
$uid
.
'@facebook.com'
);
}
}
$attributes
[
'facebook_targetedID'
]
=
array
(
'http://facebook.com!'
.
$uid
);
$attributes
[
'facebook_targetedID'
]
=
array
(
'http://facebook.com!'
.
$uid
);
$attributes
[
'facebook_cn'
]
=
array
(
$info
[
'name'
]);
$attributes
[
'facebook_cn'
]
=
array
(
$info
[
'name'
]);
\SimpleSAML\Logger
::
debug
(
'Facebook Returned Attributes: '
.
implode
(
", "
,
array_keys
(
$attributes
)));
\SimpleSAML\Logger
::
debug
(
'Facebook Returned Attributes: '
.
implode
(
", "
,
array_keys
(
$attributes
)));
$state
[
'Attributes'
]
=
$attributes
;
$state
[
'Attributes'
]
=
$attributes
;
$facebook
->
destroySession
();
$facebook
->
destroySession
();
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment