• Stars
    star
    743
  • Rank 61,046 (Top 2 %)
  • Language
    PHP
  • Created about 12 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A demo application for running an OAuth2 server

OAuth2 Demo PHP

This application is designed to demo the workflow between OAuth2.0 Clients and Servers.

If this is your first time here, try experimenting with the live demo to get a better feel for OAuth2.0 flows.

This library is running the OAuth2 Server PHP library.

Installation

Use Composer to install this application:

$ git clone git://github.com/bshaffer/oauth2-demo-php.git
$ cd oauth2-demo-php
$ curl -s http://getcomposer.org/installer | php
$ ./composer.phar install

WebHost Configuration

Configure a Web Server

Silex requires you to configure your web server to run it.

Be sure to run the command $ chmod -R 777 data/ in the project root so that the web server can create the sqlite file.

Using PHP's built-in Web Server

You can use php's built-in web server, however, you will need to spin up two instances and specify one of them in data/parameters.json in order to prevent the server from locking up. The client will issue a request to the server, and because PHP's built-in web server is single-threaded, this will result in deadlock.

$ cd oauth2-demo-php
$ cp data/parameters.json.dist data/parameters.json
$ sed -i '' 's?"grant"?"http://localhost:8081/lockdin/token"?g' data/parameters.json
$ sed -i '' 's?"access"?"http://localhost:8081/lockdin/resource"?g' data/parameters.json

Now all you have to do is spin up two separate web servers in the web directory

$ cd web
$ php -S localhost:8080 & php -S localhost:8081

Browse to http://localhost:8080 in your browser and you're all set!

What Does This App Do??

This application simulates the interaction between an OAuth2 Client (Demo App) and OAuth2 Server (Lock'd In). To get started, access the Demo App homepage:

Demo Application Homepage

Clicking Authorize will send you to Lock'd In, which mimics a data provider (such as twitter, facebook, etc). Lock'd In assumes you are already signed in, and asks if you'd like to grant the Demo app access to your information:

Lock'd In Authorization Request

Once you click Yes, I Authorize this Request, you will be redirected back to Demo App with an authorization code, which the client then exchanges for an Access Token. Demo App then makes another call to the Lock'd In APIs and uses the Access Token to retrieve the data on your behalf.

If all is successful, your data from Lock'd In will be displayed on the final page:

Demo Application Granted

The OAuth2 Client can be used to test ANY OAuth2.0 server, and can be configured to do so using the the configuration file defined below.

The OAuth2 Server

The OAuth2 Server is created (see the setup method) and then used in the Controller Classes, which implement the following endpoints:

  • /authorize - endpoint which grants the Demo App an authorization code
  • /token - endpoint which grants the Demo App an access_token when supplied with the authorization code above
  • /resource - endpoint which grants the Demo App access to your protected resources (in this case, your friends) when supplied the access token above

These are the three main functions of the OAuth2 server (authorize the user, grant the user tokens, and validate api calls). When you write your OAuth2-compatible servers, your interface will be similar.

Note: the above urls are prefixed with /server to namespace the application.

Test Your Own OAuth2 Server!

You can test this application against your own OAuth application with ease. Just copy over the parameters.json.dist file to parameters.json:

$ cd /path/to/oauth2-demo-php
$ cp data/parameters.json.dist data/parameters.json

Open the parameters.json file, and notice the default configuration:

{
  "client_id": "demoapp",
  "client_secret": "demopass",
  "token_route": "grant",
  "authorize_route": "authorize",
  "resource_route": "access",
  "resource_method": "GET",
  "resource_params": {},
  "curl_options": {}
}

This is the configuration for the default Lock'd In OAuth2 server. To test against your own, change those parameters to fit the api server you want to test against:

{
  "client_id": "OAuth Demo Application",
  "client_secret": "a3b4b74330724a927bec",
  "token_route": "https://api.myapp.com/token",
  "authorize_route": "https://myapp.com/authorize",
  "resource_route": "https://api.myapp.com/profile",
  "resource_method": "POST",
  "resource_params": { "debug": true },
  "curl_options": { "http_port": 443, "verifyssl": false }
}

The above example uses a new client to authenticate against a fictional oauth server at myapp.com. This is very useful when testing your application in production

Note: The curl options are set to ignore an SSL certificate, and the resource_params define a fictional debug parameter. These are not required for your APIs, but is meant as an example what can be done with the configuration

###Test in multiple environments

In addition, you can create multiple environments using the parameters.json file, and switch between them:

{
    "LockdIn": {
      "client_id": "demoapp",
      "client_secret": "demopass",
      "token_route": "grant",
      "authorize_route": "authorize",
      "resource_route": "access",
      "resource_method": "GET",
      "resource_params": {},
      "curl_options": {}
    },
    "My App": {
      "client_id": "OAuth Demo Application",
      "client_secret": "a3b4b74330724a927bec",
      "token_route": "https://api.myapp.com/token",
      "authorize_route": "https://myapp.com/authorize",
      "resource_route": "https://api.myapp.com/profile",
      "resource_method": "POST",
      "resource_params": { "debug": true },
      "curl_options": { "http_port": 443, "verifyssl": false }
    }
}

This will provide a dropdown at the top which will allow you to switch environments and test multiple OAuth servers

Demo Application With Environment Select

Contact

Please contact Brent Shaffer (bshafs <at> gmail <dot> com) for more information

More Repositories

1

oauth2-server-php

A library for implementing an OAuth2 Server in php
PHP
3,214
star
2

oauth2-server-php-docs

documentation for the oauth2-server-php library
CSS
229
star
3

oauth2-server-bundle

OAuth2 for your Symfony Application
PHP
107
star
4

php-echonest-api

PHP classes for the Echo Nest API
PHP
99
star
5

oauth2-server-httpfoundation-bridge

Integrate HttpFoundation into your oauth2-server library
PHP
51
star
6

csDoctrineActAsSortablePlugin

Sortable behavior for Doctrine objects
PHP
28
star
7

redmine-assets-plugin

Provides a central location to view all your project's assets
Ruby
24
star
8

phpunit-retry-annotations

Traits for retrying test methods and classes in PHPUnit
PHP
22
star
9

sfHadoriThemePlugin

symfony admin generator with a beautiful theme and clean generated code.
PHP
21
star
10

Donate-Nashville

A relief effort to connect donators with those in need
PHP
16
star
11

csDoctrineActAsGeolocatablePlugin

Automatically fetch latitude and longitude for your Doctrine model
PHP
14
star
12

Symfony-Snippets

Symfony Code Snippets
PHP
14
star
13

csSettingsPlugin

Add simple user-editable settings to your application
PHP
12
star
14

symfony-on-app-engine-flex

A demo application for symfony on app engine flexible
PHP
9
star
15

sfThemeGeneratorPlugin

Plugin for creating and extending modules using a theme
PHP
8
star
16

Symplist

Symfony Plugins List
PHP
7
star
17

csDoctrineActAsAttachablePlugin

Attachable Behavior for file uploads
PHP
6
star
18

Hadori-Demo

Demo application for the Hadori Admin Generator
PHP
6
star
19

faceswap-docker

Dockerization for the faceswap library `matthewearl/faceswap`
6
star
20

faceswap-app

Python
5
star
21

csSecurityTaskExtraPlugin

Task for assessing the security coverage of your application
PHP
4
star
22

sfUploadPlugin

An easy way to add multiple uploads to your model
PHP
3
star
23

csBackupPlugin

A plugin for easily backing up your MySQL database, Rsyncing files, etc.
Shell
3
star
24

ChartDown

Short Hand for Chart Writing
PHP
2
star
25

google-mybusiness-php-client

PHP
2
star
26

sfDoctrineMarkdownPlugin

Use the Markdown syntax for a field on your Doctrine models via a Doctrine behavior
PHP
2
star
27

dlib-elixir

dlib for Elixir
C++
2
star
28

sfImageCachePlugin

A plugin for caching images of various sizes
PHP
2
star
29

BasicParameterValidation

Basic Parameter Validator for PHP
PHP
2
star
30

format-owlbot-pr-chrome-extension

JavaScript
1
star
31

sfDoctrineActAsLocalizablePlugin

Automatically convert a localizable field using the Localizable template
PHP
1
star
32

faceswap-wordpress

PHP
1
star
33

sfHyperwordPlugin

Link words dynamically in your code to link to other pages (similar to "Wikipedia")
PHP
1
star
34

composer-git-proxy

Repository for splitting a single git repository into multiple composer packages
Shell
1
star
35

P4-CLI

Scripts to make P4 CLI easier to use
PHP
1
star
36

sfServiceContainerPlugin

A Symfony 1.4 Plugin for using the Service Container
PHP
1
star