Comments (14)
You can register a custom provider like so:
// MyCustomProvider.php
use AdamWathan\EloquentOAuth\Providers\ProviderInterface;
class MyCustomProvider implements ProviderInterface
{
// ...
}
// In your own service provider, or bootstrap/global.php, or routes.php, or wherever you want to put your bootstrapping code...
$provider = new MyCustomProvider();
OAuth::registerProvider('my-custom-provider', $provider);
The ProviderInterface is very simple (just two methods) but there's a lot of work that goes into implementing that completely from scratch. If you're trying to create a custom provider for an external service that follows the OAuth2 spec reasonably closely, using AdamWathan\EloquentOAuth\Providers\Provider
as a base class will give you a lot of stuff for free. Just check out one of the provided provider classes that implement that base class to see how it can be used.
from eloquent-oauth.
Awesome, thanks! Editing the core-files wasn't a great success with updates ;-)
from eloquent-oauth.
No prob man!
from eloquent-oauth.
Hrm doesn't look like its working but I'll probably have to fiddle some more.
from eloquent-oauth.
Here's a minimal working example that I just stuck in my routes file. Working in the sense that it proves the provider gets registered and can be used at least. Hitting http://myproject.dev/foobar/authorize
will redirect to Google.
class CustomProvider implements AdamWathan\EloquentOAuth\Providers\ProviderInterface {
public function authorizeUrl($state)
{
return 'http://www.google.com';
}
public function getUserDetails()
{
}
}
OAuth::registerProvider('foobar', new CustomProvider);
Route::get('{provider}/authorize', function($provider) {
return OAuth::authorize($provider);
});
from eloquent-oauth.
Ok, that does seem to work (better) than what I had.
But what about the access token / userdataurl functionality? As soon as someone hits the authorize link the oAuth provider claims there is an issue with the client_id parameter
from eloquent-oauth.
I think the best thing to do would be look at something like the GitHub provider as an example implementation and go from there. What provider are you trying to implement? If it's not a pretty standard OAuth provider, than the base provider class isn't going to do you any good and you are gonna have to write a lot of code from scratch, nothing that can really be done about it unfortunately.
The OAuthManager class just cares that the provider implements that interface and gives it the data it needs when it asks for it; it isn't concerned at all with how it gets that data, so the bulk of the work for communicating with the external service lives in the provider.
from eloquent-oauth.
I am using a custom oAuth server (using oauth2-server-laravel. This uses league/oauth2-server
which - AFAIK - follows the standards.
from eloquent-oauth.
Is it possible to share your code that you've written for your custom provider?
from eloquent-oauth.
The first approach I had actually cloned the one for Facebook, replaced the URL's and it was nearly working. I did have to modify the EloquentOAuthServiceProvider.php
in order to get it to work (include in the search list)
Second and third approach were based on your codes. I do not have the code right here, if its still desired I can add that tomorrow morning.
from eloquent-oauth.
If you are extending the base provider then your CustomProvider class of course needs to take a bunch of stuff in the constructor and be bootstrapped the same way the Facebook one was for example.
class CustomProvider extends AdamWathan\EloquentOAuth\Providers\Provider {
// implement all the abstract methods just like the Facebook one does
}
$config = $this->app['config']['eloquent-oauth::providers.foobar'];
$provider = new CustomProvider($config, new Guzzle\Http\Client, App::make('request'));
OAuth::registerProvider('foobar', $provider);
Route::get('{provider}/authorize', function($provider) {
return OAuth::authorize($provider);
});
And then of course change the URLs you need to from the Facebook example, rewrite anything that parses the response in a different format if it comes back differently, etc.
The initial example I gave was just to show how you register the providers. How you actually build a provider and what dependencies the provider has depends on how the provider works of course, which might usually mean it needs Guzzle (and you write the code to make Guzzle do the right requests), it needs the current Request object to get any parameters that came back from the provider itself, etc. etc. etc.
from eloquent-oauth.
Close: the $this->app
may not be used in start/global.php
or the routes but Config::Get
can. However, without the change to EloquentOAuthServiceProvider
I am still getting an Undefined index: foobar
from eloquent-oauth.
It needs an additional check whether the key is set, since it doesn't exist during initialization. PR on its way.
from eloquent-oauth.
from eloquent-oauth.
Related Issues (20)
- Not catching ApplicationRejectedException when user reject facebook login HOT 3
- Add provider - Stripe [Request]
- Seems to be incompatible with Laravel 5.1 HOT 1
- Support passing custom data into the `state` param
- Provider Request: Reddit (code provided) HOT 7
- Class 'OAuth' not found HOT 2
- Add documentation for "Designing your users table"
- Rename OAuth facade HOT 2
- Support for twitter? HOT 3
- Request FACEBOOK basic data (gender, user_friends) HOT 1
- Office365 HOT 1
- Adding a 'remember' parameter to login() method HOT 1
- Retrieving The Authenticated User HOT 2
- Merging Accounts HOT 2
- Log in by access token HOT 2
- Using Google Oauth behind proxy
- Authorize more than one provider for one user HOT 1
- Running something on register HOT 1
- ΒΏIs There a way to auth sending email and password to Facebook or google?
- 'No query results for model [App\User].' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eloquent-oauth.