Giter VIP home page Giter VIP logo

laravel-bankid's Introduction

While this package is free to use, you can hire help of integrating it, contact [email protected]

Swedish BankID for Laravel 8 with Livewire

You will need laravel 8 to use route facade but it might work with earlier versions when using middleware. Livewire is a required dependency so it will be installed. I think however its possible to quite easy call the service from another controller action and it will work quite well.

Anyway, there are a plenthora of improvements to be made to this project but it is used in production for atleast one company. PRs are very welcome.

Installation

Composer:

composer require patrikgrinsvall/laravel-bankid
  • Publish the config, views and transaltions with
php artisan vendor:publish --provider="Patrikgrinsvall\LaravelBankid\LaravelBankidServiceProvider"
  • Then check in app/config/bankid.php for info on how to add your own certificates.
  • Views will be editable in your views directory
  • Translations will be editable in defauit translations directory. Swedish and English are provided with package.

Usage

  • Service provider should be auto discovered since larvel 8 so no need to register service provider.
  • However i have noticed in many cases this does not work so usually:
  • Register service provider Patrikgrinsvall\LaravelBankid\BankidServiceProvider in config/app.php

There are a few different ways to use this package

  1. Use the supplied Route macro:
// You can change the route prefix '/bankid' to whatever you want, for example /login.
// This is then the entrypoint for where users should be sent to start authentication.
// This line of code should be placed in routes.
Route::LaravelBankid('/bankid'); 
  1. As a facade (this might work, dont remember.)
use Patrikgrinsvall\LaravelBankid\BankidFacade;
...
Bankid::login(); // will redirect user and start a login. After login user is returned to url in config/bankid.php
Bankid::user(); // returns the user previously logged in or false.
  1. As a middleware, first register in App\Http\Kernel class: (WIP! Dont use yet!)
protected $routeMiddleware = [
    'bankid' => \Patrikgrinsvall\LaravelBankid\BankidMiddleware::class,

Then use in one of the following ways:

// On a single route
Route::get('/profile', function () {
// your stuff
})->middleware('bankid');

// On a group of routes
Route::middleware([BankidMiddleware::class])->group(function () {
    Route::get('/your-route', View::render('your-route'))
});

// On a group of routes without adding to kernel
Route::middleware([\Patrikgrinsvall\LaravelBankid\BankidMiddleware::class])->group(function () {
    Route::get('/your-route', View::render('your-route'))
});

Retrieve authenticated user.

// Get the user from the session
use Illuminate\Support\Facades\Session;
...
Session::get('bankid.user');            // returns user details as an array
Session::get('bankid.personalNumber');  // returns personal number as a string
Session::get('bankid.name');            // returns full name as a string
Session::get('bankid.givenName');       // returns first name as a string
Session::get('bankid.surname');         // returns lastn name as string
Session::get('bankid.signature');       // returns signature as string.

From facade:

use Patrikgrinsvall\LaravelBankid\BankidFacade;
...
Bankid::user();

Testing

composer test

Final notes.

  • Basic authentication works for mobile devices.
  • But alot in this package is not finished i will continue to iterate over it when need arises.
  • PRs are welcome!
  • Sign is not working.
  • QR is not working.
  • Same device is not working (bankid on fil)

The MIT License (MIT). Please see License File for more information.

laravel-bankid's People

Contributors

iamlasse avatar patrikgrinsvall avatar silentpatrik avatar silentridge avatar

Watchers

 avatar  avatar

laravel-bankid's Issues

Install on Laravel 9

There are problems coming up in the log when I try to install this with L9

Problem 1
- Root composer.json requires patrikgrinsvall/laravel-bankid v0.2.0 -> satisfiable by patrikgrinsvall/laravel-bankid[v0.2.0].
- patrikgrinsvall/laravel-bankid v0.2.0 requires illuminate/contracts ^8.0 -> satisfiable by illuminate/contracts[v8.0.0, ..., 8.x-dev].

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.