Magic for Laravel

Magic for Laravel

Reference for the Magic Admin SDK for Laravel: https://github.com/magiclabs/magic-laravel

note

Looking for a PHP SDK instead? Check out:

👉 Magic Admin SDK for PHP

#Overview

The Magic Laravel SDK makes it easy to leverage Decentralized ID Tokens to authenticate your users for your app. This guide will cover some important topics for getting started with server-side APIs and to make the most of Magic's features.

  • Install the Magic Laravel SDK to get started
  • View the API documentation below to learn the methods you'll be using
  • Go to Examples for an introduction to common patterns and use-cases
note

Looking for a client-side API instead? Check out:

👉 Magic Client SDK for web

👉 Magic Client SDK for React Native

#Installation

Current SDK is built for Laravel 5.3 or newer.

#Composer

You can install the bindings via Composer. Run the following command:

01composer require magiclabs/magic-laravel

Older Laravel Installation

If you are using Laravel 5.5 or newer then skip this part. Otherwise you will need to manually register the service provider and facade alias by going to config/app.php

Add to the providers array:

01MagicLaravel\ServiceProvider::class

Add to the aliases array:

01'Magic' => MagicLaravel\Facade::class

#Setup

Publish config file.

01php artisan vendor:publish --provider="MagicLaravel\ServiceProvider"

Add MAGIC_SECRET_API_KEY to your .env file by going to the Magic Dashboard.

01MAGIC_SECRET_API_KEY=sk_XXXX_XXXXXXXXXXXXXXXX

#Creating an SDK Instance

#Get instance using the app helper

PHP
01$magic = app('MagicLaravel\Magic');
02
03$magic->token->validate('<did_token>');
04
05$magic->user->get_metadata_by_token('<did_token>');

#Get instance using the facade

PHP
01use Magic;
02
03Magic::token()->validate('<did_token>');
04
05Magic::user()->get_metadata_by_token('<did_token>');

Did you find what you were looking for?