Giter VIP home page Giter VIP logo

Comments (3)

axieum avatar axieum commented on August 19, 2024 1

I'm going to assume you've already tried following the documentation for adding a new service; http://socialiteproviders.github.io/providers/twitter/. This is basically everything you have to do; except removing the Laravel\Socialite\SocialiteServiceProvider since Laravel automatically "discovers" this package. I recommend you still install Laravel\Socialite as this gives you access to the Socialite:: facade.

Furthermore, you alongside the SocialiteProviders\Manager you'll also need install each service (Twitter, YouTube, etc.) individually. For a list of supported services, see: http://socialiteproviders.github.io/providers.


This is how I set mine up - I'd show you my repository but it's private (sorry):

When you composer require laravel/socialite`, Laravel automatically detects this package and hence you do not need to manually set things up. However, when you install Socialite Providers you'll need to do the basic setup.

In your config\app.php simply add the following line under the providers array:

SocialiteProviders\Manager\ServiceProvider::class,

Then, locate your Event Service Provider class under app\Providers\EventServiceProvider.php. Add the following array to the $listen array - this will be where you register all the events:

'SocialiteProviders\Manager\SocialiteWasCalled' => [
    // 'SocialiteProviders\Twitter\TwitterExtendSocialite@handle',
    // Simply just add more services here.
]

In order to make OAuth requests, you'll need to provide your key/id and secret alongside the request. Luckily, Socialite does this for you, all you need to do is put your keys in your .env file, or reference them in your config\services.php file.

// You only need to add this to your `config/services.php` file should you NOT put it in your `.env`.
// Just replace `env('TWITTER_KEY')` with your key; just be careful when pushing this to VC. 
'twitter' => [
    'client_id' => env('TWITTER_KEY'),
    'client_secret' => env('TWITTER_SECRET'),
    'redirect' => env('TWITTER_REDIRECT_URI'),
],

Note: most services require you to whitelist valid redirect URIs for security (only your domains can be redirected to); this redirect URI is basically the route to your callback function.

IF you installed Laravel's Socialite, then you can start making requests with Socialite::.

In your controller (or wherever), have a function that makes the request and redirects them:

return Socialite::with('twitter')->redirect();

Then, you'll need to setup a route to handle the callback:

// Retrieve the response.
$response = Socialite::driver('twitter')->user();
// dd($response); // uncomment this line to see the json response obtained.

from providers.

codeitlikemiley avatar codeitlikemiley commented on August 19, 2024 1

just to update this tread, since laravel auto package discovery is at work we dont need to add the serviceprovider on the config/app.php...

we only need to add of course the listener for the event for specific provider

from providers.

codeitlikemiley avatar codeitlikemiley commented on August 19, 2024

How do use it on laravel 5.5 anyway... can someone shed some light

from providers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.