Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class Not Found #8

Open
abdulqadir17 opened this issue Nov 29, 2017 · 8 comments
Open

Class Not Found #8

abdulqadir17 opened this issue Nov 29, 2017 · 8 comments

Comments

@abdulqadir17
Copy link

Class 'Vatsim\OAuth\OAuthServiceProvider' not found in laravel 5.3 how to add providers in config/app.php file.. kindly help me

@bonroyage
Copy link
Collaborator

What version of the package are you using? Since version 3 we separated the generic code from the Laravel specific code, which you can now find here: https://packagist.org/packages/vatsim/sso-laravel

@abdulqadir17
Copy link
Author

abdulqadir17 commented Dec 5, 2017

i am using this version of package
vatsim/sso-laravel 3.*

Kindly Provide a sample of code

@bonroyage
Copy link
Collaborator

Try following the documentation here https://packagist.org/packages/vatsim/sso-laravel.

  • The service provider is called Vatsim\OAuthLaravel\OAuthServiceProvider. It was called Vatsim\OAuth\OAuthServiceProvider on versions 1 and 2.
  • You can add the Vatsim\OAuthLaravel\SSOFacade facade as well, naming it VatsimSSO.

In composer.json, you only need vatsim/sso-laravel 3.*, since vatsim/sso 3.* will automatically be pulled in as a dependency.

config/app.php:

return [
    // ...

    'providers' => [
        // ...
        Vatsim\OAuthLaravel\OAuthServiceProvider::class,
    ],

    'aliases' => [
        // ...
        'VatsimSSO' => Vatsim\OAuthLaravel\SSOFacade:class,
    ],
];

routes:

Route::get('vatsim/login', 'VatsimController@login');
Route::get('vatsim/validate', 'VatsimController@validate');

app/Http/Controllers/VatsimController.php:

namespace App\Http\Controllers;

use VatsimSSO, Session, Redirect;

class VatsimController extends Controller {

    function login() {
        $returnUrl = '...'; // this url should go to the validate method on your site

        return VatsimSSO::login(
            $returnUrl,
            function($key, $secret, $url) {
                Session::put('vatsimauth', compact('key', 'secret'));
                return Redirect::to($url);
            },
            function($e) {
                throw $e; // Do something with the exception
            }
        );
    }

    // add method for validating the response as well
    // see https://github.com/bonroyage/vatsim-sso-laravel#validating-login

}

@abdulqadir17
Copy link
Author

Thanks my error resolve.. thank u your sample code is very helpful for me. :)

@abdulqadir17
Copy link
Author

@bonroyage hi

Please need some help

provide some configuration code.

this is my code... vastim-sso.php file
`<?php
/*

  • DO NOT PUBLISH THE KEY, SECRET AND CERT TO CODE REPOSITORIES
  • FOR SECURITY. PLEASE USE LARAVEL'S .envFILES TO PROTECT
  • SENSITIVE DATA.
  • http://laravel.com/docs/master/configuration#environment-configuration
  • Some sensible defaults have been provided so you can use .env files by adding
  • SSO_KEY, SSO_SECRET, and SSO_CERT to your .env (production).
  • NOTE THAT THE SSO_CERT MUST BE ON ONE LINE IN .env: use SSO_CERT="[private key]", replace line breaks with \n
  • Modify the three constants below to match the keys in your .env, otherwise it will use what you enter
  • on the second line of the key/secret/cert elements
    */

return [

/*
 * The location of the VATSIM OAuth interface
 */
'base'            => 'https://cert.vatsim.net/sso/auth/login/',

/*
 * The consumer key for your organisation (provided by VATSIM)
 */
'key'             => env('SSO_KEY'),

/*
* The secret key for your organisation (provided by VATSIM)
* Do not give this to anyone else or display it to your users. It must be kept server-side
*/
'secret'          => env('SSO_SECRET'),
/*
 * The URL users will be redirected to after they log in, this should
 * be on the same server as the request
 */
'return'          => 'atc.ailaanadvertising.com', //not sensitive

/*
 * The signing method you are using to encrypt your request signature.
 * Different options must be enabled on your account at VATSIM.
 * Options: RSA / HMAC
 */
'method'          => 'HMAC',

/*
 * Your RSA **PRIVATE** key
 * If you are not using RSA, this value can be anything (or not set)
 */
'cert'            => env('SSO_CERT'),

/*
 * Set to true to allow suspended users to sign in
 */
'allow_suspended' => false,

/*
 * Set to true to allow inactive users to sign in
 */
'allow_inactive'  => false,

];
`

And Route:

Route::get('login', 'VatsimController@login');
Route::get('validate', 'VatsimController@validate');

and Controller,

`function login() {
$returnUrl = '...'; // this url should go to the validate method on your site

    return VatsimSSO::login(
        $returnUrl,
        function($key, $secret, $url) {
            Session::put('vatsimauth', compact('key', 'secret'));
            return Redirect::to($url);
        },
        function($e) {
            throw $e; // Do something with the exception
        }
    );
}`

ScreenShot Attached. Errors
https://goo.gl/HedDN7

@abdulqadir17 abdulqadir17 reopened this Dec 12, 2017
@bonroyage
Copy link
Collaborator

Did you add your environment variables? From your screenshot it looks like you didn't add a key, your returnUrl is still set to "..."

@abdulqadir17
Copy link
Author

abdulqadir17 commented Dec 13, 2017

What is environment variables?
i put return url and keys and show this error i attached image
screencapture-atcbooking-vatsim-login-1513170068858

@bonroyage
Copy link
Collaborator

For the environment config, please see the Laravel documentation: https://laravel.com/docs/5.3/configuration#environment-configuration

So in the vatsim-sso.php config file, you'll see it refers to env('SSO_KEY'), env('SSO_SECRET'), etc. These are the ones you have received from VATSIM. This is also clearly explained in the comments at the top of the configuration file.

In your .env file you can write them like

SSO_KEY=[key here]
SSO_SECRET=[secret here]

Imagine your domain is example.com and you configured the two routes:

Route::get('login', ['name' => 'vatsim.login', 'uses' => 'VatsimController@login']);
Route::get('validate', ['name' => 'vatsim.validate', 'uses' => 'VatsimController@validate']);

Then for a user to login, they go to example.com/login. In the controller method, your return URL should be example.com/validate, which you can easily add by writing route('vatsim.validate') as long as you've named the routes like above. After finishing the authentication on VATSIM's side, VATSIM will redirect back to example.com/validate with some data that you then use to get the user and log them in on your app.

$session = Session::get('vatsimauth'); // this was set in the login method 

return VatsimSSO::validate(
    $session['key'],
    $session['secret'],
    Input::get('oauth_verifier'), // this is what VATSIM returns
    function($user, $request) {
        // At this point we can remove the session data.
        Session::forget('vatsimauth');
        
        /**
         * this is where we log the user in on our own app, but note that
         * this is very basic, as we have not checked if the user exists
         * in our own database yet, so you might want to create the user first
         */
        Auth::loginUsingId($user->id);
        return Redirect::home();
    },
    function($error) {
        throw $e; // Do something with the exception
    }
);

I also suggest you check out the forums where there are multiple pinned threads that explain how it works: https://forums.vatsim.net/viewforum.php?f=134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants