Skip to content

Commit

Permalink
Removed Laravel specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
bonroyage committed Feb 22, 2017
1 parent eb40b1b commit 157ca96
Show file tree
Hide file tree
Showing 11 changed files with 503 additions and 744 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 KHardern
Copyright (c) 2017 KHardern

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
104 changes: 20 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,23 @@
VatsimSSO
=========

**Laravel 5 compatible, use version 1 for Laravel 4**
**Version:** 3.0

The VatsimSSO package integrates with the VATSIM.net Single Sign On, which lets your users log themselves in using their VATSIM ID. This is especially useful for official vACCs and ARTCCs.

Version
----

2.0
**For Laravel integration, see VatsimSSO for Laravel.**

Installation
--------------

Use [Composer](http://getcomposer.org) to install the VatsimSSO and dependencies.

```sh
$ composer require vatsim/sso 2.*
```

### Laravel
#### Set up
Using VatsimSSO in Laravel is made easy through the use of Service Providers. Add the service provider to your `config/app.php` file:
```php
'providers' => array(
// ...
'Vatsim\OAuth\OAuthServiceProvider',
),
$ composer require vatsim/sso 3.*
```

Followed by the alias:
```php
'aliases' => array(
// ...
'VatsimSSO' => 'Vatsim\OAuth\Facades\SSO',
),
```

#### Configuration file
Use artisan to publish the configuration file. After running the command you will find the file in `config/vatsim-sso.php`. Change the settings accordingly.
```sh
$ artisan vendor:publish
```
It is __strongly__ recommended you use Laravel's built-in suppport for environment files to protect sensitive data. Additional details in config.php


### Outside Laravel
### Set up
Let's first create a configuration file to keep our code clean.
```php
/*
Expand Down Expand Up @@ -87,6 +59,11 @@ $cert = '';
* be on the same server as the request
*/
$return = 'http://example.com/valiatelogin';

$additionalConfig = [
'allow_suspended' => false,
'allow_inactive' => true,
];
```

Now, let's initialise the SSO class.
Expand All @@ -98,7 +75,7 @@ require 'config.php';

use Vatsim\OAuth\SSO;

$sso = new SSO($base, $key, $secret, $method, $cert);
$sso = new SSO($base, $key, $secret, $method, $cert, $additionalConfig);
```

## Usage
Expand All @@ -107,36 +84,18 @@ The first step would be to send a request to VATSIM to let the user login. The e
#### Parameters
| Parameter | Type | Description |
| --------------- | ------ | ----------- |
| `$returnUrl` | string | array | The URL to which the user should be redirected after the login is successful |
| `$success` | string | Closure | Callback function containing the actions needed to be done when you are able to let the user authenticate (ie. when your key/secret are correct). The function will return three variables: `$key`, `$secret` and `$url`. |
| *`$error`* | string | Closure | *Default: null* – Callback function containing the actions needed to be done when your credentials (ie. key/secret) are incorrect. |

For both `$success` and `$error`, you may pass a string in `[class]@[method]` format to call a function in another Model, otherwise pass an anonymous function.

#### Return URL
The return URL parameter will also take an array instead of a string. In this array you can add the values `suspended` and/or `inactive` to allow members with suspended or inactive accounts to log in. The first element of this array that is a valid URL will be used as the return URL.
| `$returnUrl` | string | The URL to which the user should be redirected after the login is successful |
| `$success` | Closure | Callback function containing the actions needed to be done when you are able to let the user authenticate (ie. when your key/secret are correct). The function will return three variables: `$key`, `$secret` and `$url`. |
| *`$error`* | Closure | *Default: null* – Callback function for error handling. The function will provide one argument: an instance of `VATSIM\OAuth\SSOException`. If no callback is provided, the `SSOException` will be thrown. |

#### Success
The success parameter returns three variables: `$key`, `$secret` and `$url`. The `key` and `secret` should be stored in a session for the validation process. The `url` will be used to redirect the user to the VATSIM SSO site.
The success parameter provides three arguments: `$key`, `$secret` and `$url`. The `key` and `secret` should be stored in a session for the validation process. The `url` will be used to redirect the user to the VATSIM SSO site.

#### Error
Optional parameter. If this parameter is ignored and an error occurs, the function will return `false`. If you pass a function then one parameter will be returned `$error`, which is an array of data related to the last error.
Optional parameter. If this parameter is ignored and an error occurs, a `SSOException` will be thrown. If you pass a function then one parameter will be returned `$error`, which is the instance of `SSOException`.

#### Example
```php
// Laravel
return VatsimSSO::login(
Config::get('vatsim-sso.return'),
function($key, $secret, $url) {
Session::put('vatsimauth', compact('key', 'secret'));
return Redirect::to($url);
},
function($error) {
throw new Exception('Could not authenticate: ' . $error['message']);
}
);

// Outside Laravel
$sso->login(
$return,
function($key, $secret, $url) {
Expand All @@ -147,7 +106,7 @@ $sso->login(
);
```

If you prefer not to use the `->login()` function, you may use `->requestToken($returnUrl)`. This will return an object containing the `key` and `secret` or returns `false` if an error occurs, at that point you can use `->error()` to get the array of the last occured error. Then use `->sendToVatsim()` to get the URL for the redirect.
If you prefer not to use the `->login()` function, you may use `->requestToken($returnUrl)`. This will return an object containing the `key` and `secret` or throw `VATSIM\OAuth\SSOException` if an error occurs. Then use `->redirectUrl()` to get the URL for the redirect.

### Validating login
After the login has been successful, we need to get the user data from VATSIM. Also for this we wrote a function to make it easier for you.
Expand All @@ -157,39 +116,17 @@ After the login has been successful, we need to get the user data from VATSIM. A
| `$key` | string | The `key` stored in the session at login |
| `$secret` | string | The `secret` stored in the session at login |
| `$verifier` | string | The `oauth_verifier` passed in the query string |
| `$success` | string | Closure | Callback function containing the actions needed to be done when the login has been successful. |
| *`$error`* | string | Closure | *Default: null* – Callback function containing the actions needed to be done when authentication was unsuccessful (could be because of wrong key/secret/verifier) |

For both `$success` and `$error`, you may pass a string in `[class]@[method]` format to call a function in another Model, otherwise pass an anonymous function.
| `$success` | Closure | Callback function containing the actions needed to be done when the login has been successful. |
| *`$error`* | Closure | *Default: null* – Callback function for error handling (could be because of wrong key/secret/verifier). The function will provide one argument: an instance of `VATSIM\OAuth\SSOException`. If no callback is provided, the `SSOException` will be thrown. |

#### Success
The success parameter returns two variables: `$user` and `$request`. The `user` variable will be an object containing all user data available to your organisation. The `request` variable will give you information about the request.

#### Error
Optional parameter. If this parameter is ignored and an error occurs, the function will return `false`. If you pass a function then one parameter will be returned `$error`, which is an array of data related to the last error.
Optional parameter. If this parameter is ignored and an error occurs, a `SSOException` will be thrown. If you pass a function then one parameter will be returned `$error`, which is the instance of `SSOException`.

#### Example
```php
// Laravel
$session = Session::get('vatsimauth');

return VatsimSSO::validate(
$session['key'],
$session['secret'],
Input::get('oauth_verifier'),
function($user, $request) {
// At this point we can remove the session data.
Session::forget('vatsimauth');

Auth::loginUsingId($user->id);
return Redirect::home();
},
function($error) {
throw new Exception('Could not authenticate: ' . $error['message']);
}
);

// Outside Laravel
$session = $_SESSION['vatsimauth'];

$sso->validate(
Expand All @@ -210,8 +147,7 @@ $sso->validate(
);
```

If you prefer not to use the `->validate()` function, you may use `->checkLogin($key, $secret, $verifier)`. This will return an object containing the `user` and `request` objects or returns `false` if an error occurs, at that point you can use `->error()` to get the array of the last occured error.

If you prefer not to use the `->validate()` function, you may use `->checkLogin($key, $secret, $verifier)`. This will return an object containing the `user` and `request` objects or throw `VATSIM\OAuth\SSOException` if an error occurs.

License
----
Expand Down
43 changes: 20 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
{
"name": "vatsim/sso",
"description": "VATSIM OAuth",
"keywords": [
"name" : "vatsim/sso",
"description" : "VATSIM OAuth",
"keywords" : [
"vatsim",
"oauth",
"laravel",
"sso"
],
"license": "MIT",
"authors": [
"license" : "MIT",
"authors" : [
{
"name": "Kieran Hardern",
"email": "[email protected]"
"name" : "Kieran Hardern",
"email" : "[email protected]"
},
{
"name": "Roy de Vos Burchart",
"email": "[email protected]",
"homepage": "http://www.bonroyage.com"
"name" : "Roy de Vos Burchart",
"email" : "[email protected]",
"homepage" : "http://www.bonroyage.com"
}
],
"support": {
"issues": "https://github.com/KHardern/VatsimSSO/issues",
"wiki": "https://github.com/KHardern/VatsimSSO/wiki"
"support" : {
"issues" : "https://github.com/KHardern/VatsimSSO/issues",
"wiki" : "https://github.com/KHardern/VatsimSSO/wiki"
},
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.*",
"illuminate/container": "5.*",
"bonroyage/oauth": "1.*"
"require" : {
"php" : ">=5.4.0",
"bonroyage/oauth" : "1.*"
},
"autoload": {
"psr-0": {
"Vatsim\\OAuth": "src/"
"autoload" : {
"psr-4" : {
"Vatsim\\OAuth\\" : "src/"
}
},
"minimum-stability": "dev"
"minimum-stability" : "dev"
}
25 changes: 25 additions & 0 deletions src/RsaSha1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php namespace Vatsim\OAuth;

use Eher\OAuth\RsaSha1 as BaseRsaSha1;
use Eher\OAuth\OAuthException;

class RsaSha1 extends BaseRsaSha1 {

private $cert = false;

public function __construct ( $cert )
{
$this->cert = $cert;
}

public function fetch_private_cert ( &$request )
{
return $this->cert;
}

public function fetch_public_cert ( &$request )
{
throw new OAuthException("fetch_public_cert not implemented");
}

}
Loading

0 comments on commit 157ca96

Please sign in to comment.