Giter Club home page Giter Club logo

laravel8-api-auth-passport-socialite's Introduction

laravel8-api-auth-passport-socialite

Laravel 8 REST API Authentication with Passport and Socialite

Install Laravel

$ composer create-project laravel/laravel

Install passport

$ composer require laravel/passport

Run the Artisan migrate command:

$ php artisan migrate

Create "personal access" and "password grant" clients which will be used to generate access tokens:

$ php artisan passport:install

Install passport config

$ php artisan passport:keys
$ php artisan vendor:publish --tag=passport-config
$ php artisan vendor:publish --tag=passport-migrations

Install socialite

$ composer require laravel/socialite

Auth with Social Account API:

php artisan make:model SocialAccount -m

php artisan make:migration make_password_and_email_fields_nullable_in_users_table --table=users

Create an SocialAccountsService in App\Services\SocialAccountsService

Start the local development server

php artisan serve

You can now access the server at http://127.0.0.1:8000

Make sure you set the correct database connection information before running the migrations

php artisan migrate 
php artisan serve

API Routes

HTTP Method Path Desciption
GET api/auth/redirect/{provider} redirect to provider - social redirect
GET api/auth/{provider}/callback callback url - social register/login
POST api/register API normal user register via passport
POST api/login API normal user login via passport

Note: /api/auth/redirect/{provider} /api/auth/{provider}/callback is a auth routes for getting register & login the user via social login.

Note:

  • You can now use:

  • GET api/auth/redirect/google โ€“> Create user via google provider

    	{
    	  "success": true,
    	  "data": {
    		"provider_redirect": "https://accounts.google.com/o/oauth2/auth?client_id={client_key}&redirect_uri={callback_url}&scope=openid+profile+email&response_type=code"
    	  },
    	  "message": "Provider 'google' redirect url."
    	}
    
  • GET api/auth/google/callback โ€“> with code to obtain a access token

And remember, Passport requires you to provide the token as a header.

Run APIs

Let's run API through postman.

Run authentication API to get passport access token & copy the token and use the same in Header of other CRUD APIs.

Please check the laravel8-api-auth-passport-socialite documentation - The collection published URL. API Documentation

laravel8-api-auth-passport-socialite's People

Contributors

savitha7 avatar

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.