How to know whether the request is an ajax request or normal request in PHP?
We can know it through following code:
$ajax = false;
if(!empty($_SERVER['HTTP_X_
$ajax = true;
}
echo $ajax;
$ su -c 'yum install git php-pdo php httpd'
$ sudo apt-get install git sqlite3 php5 php5-sqlite
chown line you need to use your own user account name!$ cd /var/www/html
$ su -c 'mkdir php-oauth'
$ su -c 'chown fkooman:fkooman php-oauth'
$ git clone git://github.com/fkooman/php-oauth.git
$ cd php-oauth
$ sh docs/install_dependencies.sh
$ docs/configure.sh
config/oauth.ini, and possibly other settings. If you want to keep using SQlite you are good to go without fiddling with the database settings. Now to initialize the database, i.e. to install the tables, run:$ php docs/initOAuthDatabase.php
docs/registration.json. By default they point to http://localhost, but if you run this software on a "real" domain you need to modify the docs/registration.json file to point to your domain name and full path where the management clients will be installed.$ sed 's|http://localhost|https://www.example.org|g' docs/registration.json > docs/myregistration.json
docs/myregistration.json by hand if you desire, and then load them in the database:$ php docs/registerClients.php docs/myregistration.json
/var/www/php-oauth and not in /var/www/html/php-oauth and you usesudo instead of su -c.config/oauth.ini.data/ directory to allow Apache to write to the directory. If you want to use the BrowserID authentication plugin you also need to give Apache permission to access the network. These permissions can be given by using setsebool as root:$ sudo setsebool -P httpd_can_network_connect=on
$ sudo setsebool -P httpd_can_sendmail=on
data/ directory to survive file system relabeling you have to update the policy as well.docs/apache.conf./etc/httpd/conf.d/php-oauth.conf. On Debian based distributions the file can be placed in /etc/apache2/conf.d/php-oauth. Be sure to modify it to suit your environment and do not forget to restart Apache.docs/configure.sh script from the previous section outputs a config for your system which replaces the /PATH/TO/APP with the actual install directory.DummyResourceOwner - one static account configured in config/oauth.iniSspResourceOwner - simpleSAMLphp plugin for SAML authenticationBrowserIDResourceOwner - BrowserID / Mozilla Persona pluginauthenticationMechanism setting in config/oauth.ini.php-oauth API. It is possible to write a client application that uses the php-oauth API to manage OAuth client registrations. The problem now is how to decide who is allowed to manage OAuth client registrations. Clearly not all users who can successfully authenticate, but only a subset. The way now to determine who gets to do what is accomplished through entitlements.[Api] section the management API can be enabled:[Api]
enableApi = TRUE
urn:vnd:oauth2:applications entitlement in order to be able to modify application registrations. The entitlements are part of the resource owner's attributes. This maps perfectly to SAML attributes obtained through the simpleSAMLphp integration.DummyResourceOwner section, the user has this entitlement as shown in the snippet below:; Dummy Configuration
[DummyResourceOwner]
resourceOwnerId = "1234-5678-9999"
[DummyResourceOwnerAttributes]
uid[] = "fkooman"
displayName[] = "François Kooman"
eduPersonEntitlement[] = "urn:vnd:oauth2:applications"
eduPersonEntitlement[] = "foo"
eduPersonEntitlement[] = "bar"
urn:vnd:oauth2:applications, foo and bar entitlements. As there is only one account in the DummyResourceOwner configuration it is quite boring.SspResourceOwner configuration it is a little bit more complex. Dealing with this is left to the simpleSAMLphp configuration and we just expect a certain configuration.config/oauth.ini only a few aspects can be configured. To configure the SAML integration, make sure the following settings are at least correct.authenticationMechanism = "SspResourceOwner"
; simpleSAMLphp configuration
[SspResourceOwner]
sspPath = "/var/simplesamlphp"
authSource = "default-sp"
metadata/saml20-idp-remote.php to configure the IdP that is used by the simpleSAMLphp as SP:$metadata['http://localhost/simplesaml/saml2/idp/metadata.php'] = array(
'SingleSignOnService' => 'http://localhost/simplesaml/saml2/idp/SSOService.php',
'SingleLogoutService' => 'http://localhost/simplesaml/saml2/idp/SingleLogoutService.php',
'certFingerprint' => '4bff319a0fa4903e4f6ed52956fb02e1ebec5166',
// clean up the attributes received from the IdP and modify them to use
// our naming convention
'authproc' => array(
50 => array(
'class' => 'core:AttributeMap',
'urn2name',
),
),
);
50 changes the attributes to their base name. For example, if your IdP provides theurn:mace:dir:attribute-def:eduPersonEntitlement attribute, this is now reduced to just eduPersonEntitlement, the same for all the other urn:mace prefixed attributes.Bearer token you receive from the client. It is the same API as used by Google.Authorization header from the client:Authorization: Bearer eeae9c3366af8cb7acb74dd5635c44e6
$ curl http://localhost/php-oauth/tokeninfo.php?access_token=eeae9c3366af8cb7acb74dd5635c44e6
{
"attributes": {
"displayName": [
"Margie Korn"
],
"eduPersonEntitlement": [
"urn:vnd:grades:administration"
],
"uid": [
"teacher"
]
},
"audience": "html-view-grades",
"client_id": "html-view-grades",
"expires_in": 3567,
"resource_owner_id": "6b976124bc1747b3e8b249fe3bd6edff16d546ac",
"scope": "grades",
"user_id": "6b976124bc1747b3e8b249fe3bd6edff16d546ac"
}
HTTP/1.1 400 Bad Request
{"error":"invalid_token","error_description":"the token was not found"}
resource_owner_id or its alias user_id SHOULD to be used for that. Thescope field can be used to determine the scope the client was granted by the resource owner.client_id field or its alias audience matches the OAuth client ID they registered at the service.