Magic admin PHP SDK makes it easy to leverage Decentralized ID tokens to protect routes and restricted resources for your application.

Overview

Magic Admin PHP SDK

The Magic Admin PHP SDK provides convenient ways for developers to interact with Magic API endpoints and an array of utilities to handle DID Token.

Table of Contents

Documentation

See the Magic doc!

Installation

Composer

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

composer require magiclabs/magic-admin-php

To use the bindings, use Composer's autoload:

require_once __DIR__ . '/vendor/autoload.php';

Manual Installation

If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the init.php file.

require_once __DIR__ . '/path/to/magic-admin-php/init.php';

Dependencies

The bindings require the following extensions in order to work properly. If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.

For optimal performance ensure that your platform has the gmp extension installed. If your platform does not support gmp then bcmath may be used as an alternative, but note that bcmath is significantly slower than gmp.

Since gmp is a required dependency you may need to use the --ignore-platform-reqs flag when runnining composer install on a platform without the gmp extension.

Prerequisites

PHP 5.6.0 and later.

Quick Start

Simple usage for login:

  require_once __DIR__ . '/vendor/autoload.php';

  $did_token = \MagicAdmin\Util\Http::parse_authorization_header_value(
    $authorization_header
  );

  if ($did_token === null) {
    // DIDT is missing from the original HTTP request header. You can handle this by
    // remapping it to your application error.
  }

  $magic = new \MagicAdmin\Magic('<YOUR_API_SECRET_KEY>');

  try {
    $magic->token->validate($did_token);
    $issuer = $magic->token->get_issuer($did_token);
  } catch (\MagicAdmin\Exception\DIDTokenException $e) {
    // DIDT is malformed. You can handle this by remapping it
    // to your application error.
  }

Configure Network Strategy

The Magic object also takes in retries, timeout and backoff as optional arguments at the object instantiation time so you can override those values for your application setup.

$magic = new \MagicAdmin\Magic(
  '<YOUR_API_SECRET_KEY>',
  5,    // timeout
  3,    // retries
  0.01  // backoff
);

See more examples from Magic PHP doc.

Development

Get Composer. For example, on Mac OS:

brew install composer

Install dependencies:

composer install

Install dependencies as mentioned above (which will resolve PHPUnit), then you can run the test suite:

./vendor/bin/phpunit tests/

Or to run an individual test file:

./vendor/bin/phpunit tests/MagicTest.php

The library uses PHP CS Fixer for code formatting. PHP CS Fixer must be installed globally. Code must be formatted before PRs are submitted. Run the formatter with:

php-cs-fixer fix -v --using-cache=no .

Changelog

See Changelog

License

See License

Comments
  • Add support for runtimes without gmp

    Add support for runtimes without gmp

    📦 Pull Request

    This pull implements an alternate ecRecover process internally as opposed to using digitaldonkey/ecverify. This is due to the reasons described in this issue. In summary this pull will allow this package to support runtimes that do not have the gmp extension installed as long as the bcmath extension is installed.

    No new functionality has been introduced.

    One thing to note is that although calls to $magic->token->validate() will work without gmp as long as bcmath is installed, there is a significant performance difference between the two. This is why the simplito/bigint-wrapper-php sub-dependency is designed to work with gmp first and bcmath as a fallback.

    On average calls to $magic->token->validate() took about 17ms with gmp versus 320ms with bcmath. In apps where validate is being called on every request this may be a showstopper for some users.

    Users should be encouraged to install gmp whenever possible, but also made aware that the package will work with bcmath as an alternative. Currently there are various hosting platforms that do not support gmp, like Laravel Vapor for example.

    🗜 Versioning

    (Check one!)

    • [x] Patch: Bug Fix?
    • [ ] Minor: New Feature?
    • [ ] Major: Breaking Change?
    opened by brianrlewis 2
  • Support mult-chain wallets in get_metadata calls

    Support mult-chain wallets in get_metadata calls

    📦 Pull Request

    The current implementation of magic-admin-php for metadata retrieval returns the Ethereum public_address.

    We are adding functionality to query wallet(s) for any chain tied to the end-user.

    Example (queries all Solana wallets created for the user if applicable): $meta = $magic->user->get_metadata_by_token_and_wallet($did_token, \MagicAdmin\Resource\Wallet::SOLANA);

    Example (queries all wallets created for the user if applicable): $meta = $magic->user->get_metadata_by_token_and_wallet($did_token, \MagicAdmin\Resource\Wallet::ANY);

    Please see supported wallet types in lib/Resource/Wallet.php.

    🗜 Versioning

    (Check one!)

    • [ ] Patch: Bug Fix?
    • [x] Minor: New Feature?
    • [ ] Major: Breaking Change?

    ✅ Fixed Issues

    • [List any fixed issues here like: Fixes #XXXX]

    🚨 Test instructions

    ./vendor/bin/phpunit tests  3.0.0 02:30:07 PM PHPUnit 8.5.31 by Sebastian Bergmann and contributors.

    .................................................. 50 / 50 (100%)

    Time: 74 ms, Memory: 8.00 MB

    OK (50 tests, 83 assertions)

    ⚠️ Update CHANGELOG.md

    • [x] I have updated the Upcoming Changes section of CHANGELOG.md with context related to this Pull Request.
    opened by justinnout 1
  • Release v0.1.3

    Release v0.1.3

    📦 Pull Request

    Release v0.1.3

    🗜 Versioning

    (Check one!)

    None

    ✅ Fixed Issues

    None

    🚨 Test instructions

    [Describe any additional context required to test the PR/feature/bug fix.]

    ⚠️ Update CHANGELOG.md

    • [X] I have updated the Upcoming Changes section of CHANGELOG.md with context related to this Pull Request.
    opened by brianrlewis 0
  • Release v0.1.2

    Release v0.1.2

    📦 Pull Request

    Release v0.1.2

    🗜 Versioning

    (Check one!)

    None

    ✅ Fixed Issues

    None

    🚨 Test instructions

    [Describe any additional context required to test the PR/feature/bug fix.]

    ⚠️ Update CHANGELOG.md

    • [x] I have updated the Upcoming Changes section of CHANGELOG.md with context related to this Pull Request.
    opened by FYJen 0
  • Use isset to check if a key exists in the claim array to support PHP7.4

    Use isset to check if a key exists in the claim array to support PHP7.4

    📦 Pull Request

    Use isset to check if a key exists in the claim array to support PHP7.4

    🗜 Versioning

    (Check one!)

    • [x] Patch: Bug Fix?
    • [ ] Minor: New Feature?
    • [ ] Major: Breaking Change?

    ✅ Fixed Issues

    • Fixes https://github.com/magiclabs/magic-admin-php/issues/6

    🚨 Test instructions

    • Tests passed
    • Manually verified with PHP7.4

    ⚠️ Update CHANGELOG.md

    • [x] I have updated the Upcoming Changes section of CHANGELOG.md with context related to this Pull Request.
    opened by itprodev 0
  • Exception: Using array_key_exists() on objects is deprecated in PHP 7.4

    Exception: Using array_key_exists() on objects is deprecated in PHP 7.4

    ✅ Prerequisites

    • [X] Did you perform a cursory search of open issues? Is this bug already reported elsewhere?
    • [X] Are you running the latest SDK version?
    • [x] Are you reporting to the correct repository (magic-admin-php)?

    🐛 Description

    /lib/Resource/Token.php:26 throws an exception in PHP 7.4:

    ErrorException: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead

    Using array_key_exists() on objects is deprecated in PHP 7.4.

    🧩 Steps to Reproduce

    1. composer require magiclabs/magic-admin-php
    2. (Get $did_token from client)
    3. $magic = new \MagicAdmin\Magic(env('MAGIC_SECRET'));
    4. $magic->token->validate($did_token); or $issuer = $magic->token->get_issuer($did_token);

    🤔 Expected behavior

    Validate or get issuer from the DID token

    😮 Actual behavior

    ErrorException: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead
    
    /.../vendor/magiclabs/magic-admin-php/lib/Resource/Token.php:26
    /.../vendor/magiclabs/magic-admin-php/lib/Resource/Token.php:66
    /.../vendor/magiclabs/magic-admin-php/lib/Resource/Token.php:73
    

    💻 Code Sample

    $magic = new \MagicAdmin\Magic(env('MAGIC_SECRET_KEY'));
    try {
        $magic->token->validate($did_token);
        $issuer = $magic->token->get_issuer($did_token);
    } catch (\MagicAdmin\Exception\DIDTokenException $e) {
        dd($e->getErrorMessage());
    }
    

    🌎 Environment

    | Software | Version(s) | | ------------------- | ---------- | | magic-admin-php | 0.1.0 | | php | 7.4.12 | | Operating System | macOS 10.15.7 |

    🐛 Bug Report 
    opened by ArcadeCityMayor 0
  • Fix composer autoload issue

    Fix composer autoload issue

    📦 Pull Request

    An attempt to fix composer autoload issue

    🗜 Versioning

    (Check one!)

    • [x] Patch: Bug Fix?
    • [ ] Minor: New Feature?
    • [ ] Major: Breaking Change?

    ✅ Fixed Issues

    • N/A

    🚨 Test instructions

    Minimal

    ⚠️ Update CHANGELOG.md

    • pre-release
    opened by FYJen 0
  • Include provenance and more to user meta data

    Include provenance and more to user meta data

    ✅ Prerequisites

    • [x] Did you perform a cursory search of open issues? Is this feature already requested elsewhere?
    • [x] Are you reporting to the correct repository (magic-admin-php)?

    ✨ Feature Request

    Hi, could you include more data to /v1/admin/auth/user/get and let end users (us) decide which specific piece of data should be made useful. From the perspective of single-responsibility principle, it makes sense that provenance, signup_ts and more belong to user meta data. Also adding them wouldn't break any existing functionalities.

    Or you already have APIs available for more user data?

    🧩 Context

    This feature request is to accommodate the inability of linking email and social logins on your platform. In our system, we'd like to direct all logins with the same email address to one account. We've managed to associate link login and social logins to one account on our end, but there is a security issue in which it is possible to generate a Magic token from social login and use the token to access the API for link login. We need to check provenance to make sure users do not abuse our APIs.

    Another way is to make use of the add field in a DID token, which is not available to us neither https://magic.link/docs/introduction/decentralized-id#decentralized-id-token-specification

    A hard way is to maintain a table on our own and sync with https://api.magic.link/v2/dashboard/magic_client/users?magic_client_id=[MAGIC_CLIENT_ID]=&limit=10&offset=50&include_count=1 which gives us provenance. It's impossible to happen due to the complexity, it would also double the time spent on login.

           {
                    "id": [EMAIL_ADDR]',
                    "magic_client_id": [CLIENT_ID],
                    "provenance": "LINK",
                    "signup_ts": 1625162812
            },
            {
                    "id": [EMAIL_ADDR]',
                    "magic_client_id": [CLIENT_ID],
                    "provenance": "apple",
                    "signup_ts": 1625162812
            },
    

    💻 Examples

    {
        "data": {
            "email": [EMAIL],
            "issuer": [ISSUER],
            "public_address": [PUBLIC_ADDRESS],
            "provenance": [PROVENANCE],
            ...
        },
        ...
    }
    
    ✨Feature Request 
    opened by captain-melanie 0
Owner
magiclabs
Make passwords disappear with a touch of Magic 🧙‍♂️
magiclabs
This system will provide security and comfortable opportunities to protect your gaming account.

VK Security – Auth system VK Security provides the ability to use game authorization inside in conjunction with the official VKontakte groups. Conveni

Victor Kasko 4 Dec 21, 2022
Learn Cookies and Tokens Security in Practice.

The full article is posted on my blog. The video presentation is shared here. The presentation slides are shared here. The exploit codes are shared he

HolyBugx 38 Aug 28, 2022
Easily define tokens and options that can be replaced in strings.

Token Replace This simple package allows you to define tokens that can be replaced in strings. Instead of a simple str_replace, Token Replace lets you

Jamie Holly 2 Dec 21, 2022
A simple, safe magic login link generator for Laravel

Laravel Passwordless Login A simple, safe magic login link generator for Laravel This package provides a temporary signed route that logs in a user. W

gro.sv 689 Dec 25, 2022
PASETO: Platform-Agnostic Security Tokens

PASETO: Platform-Agnostic Security Tokens Paseto is everything you love about JOSE (JWT, JWE, JWS) without any of the many design deficits that plague

Paragon Initiative Enterprises 3.1k Dec 27, 2022
Implements a Refresh Token system over Json Web Tokens in Symfony

JWTRefreshTokenBundle The purpose of this bundle is manage refresh tokens with JWT (Json Web Tokens) in an easy way. This bundles uses LexikJWTAuthent

Marcos Gómez Vilches 568 Dec 28, 2022
permission generation for all your declared routes with corresponding controller action

Permissions Generator This package add some artisan command to help generating permissions for your declared routes. Each route should have an alias (

Diagana Mouhamed Fadel 4 Nov 30, 2022
Tech-Admin is Laravel + Bootstrap Admin Panel With User Management And Access Control based on Roles and Permissions.

Tech-Admin | Laravel 8 + Bootstrap 4 Tech-Admin is Admin Panel With Preset of Roles, Permissions, ACL, User Management, Profile Management. Features M

TechTool India 39 Dec 23, 2022
Routes and Middleware for Using OAuth2 Server within a Slim Framework API

Chadicus\Slim\OAuth2 A collection of OAuth2 Server routes, middleware and utilities for use within a Slim 3 Framework API Requirements Chadicus\Slim\O

Chad Gray 126 Oct 8, 2022
A simple twitter SDK to interact with Twitter api (1.1)

Twitter SDK Installation composer require lyrixx/twitter-sdk Usage Create a twitter application then <?php require __DIR__.'/vendor/autoload.php';

Grégoire Pineau 37 Aug 28, 2020
PHP Client and Router Library for Autobahn and WAMP (Web Application Messaging Protocol) for Real-Time Application Messaging

Thruway is an open source client and router implementation of WAMP (Web Application Messaging Protocol), for PHP. Thruway uses an event-driven, non-blocking I/O model (reactphp), perfect for modern real-time applications.

Voryx 662 Jan 3, 2023
Open source social sign on PHP Library. HybridAuth goal is to act as an abstract api between your application and various social apis and identities providers such as Facebook, Twitter and Google.

Hybridauth 3.7.1 Hybridauth enables developers to easily build social applications and tools to engage websites visitors and customers on a social lev

hybridauth 3.3k Dec 23, 2022
Multi Auth and admin auth in Laravel Project

Laravel Multi Auth For Complete Documentation, visit Here This package is just create admin side (multi auth), which is totaly isolated from your norm

Bitfumes 435 Dec 31, 2022
Sliding captcha for dcat-admin auth / dcat-admin登陆 滑动验证插件 多平台支持

dcat-admin登陆 滑动验证插件 多平台支持 dcat-admin登陆 滑动验证插件 多平台支持 另有 laravel-admin版 Demo演示 演示站点(暂时无,目前地址为laravel-admin版的演示地址) 支持(按照字母顺序) 顶象 ✔️ 极验 ✔️ hCaptcha(和谷歌Rec

塵世不再 38 Dec 17, 2022
Admin Autologin for Magento 2

Admin Autologin for Magento 2 The simple extension that allows to perform admin log in automatically without asking for login/password. Useful for dem

Yaroslav Rogoza 15 Jan 18, 2022
PHPoAuthLib provides oAuth support in PHP 7.2+ and is very easy to integrate with any project which requires an oAuth client.

PHPoAuthLib NOTE: I'm looking for someone who could help to maintain this package alongside me, just because I don't have a ton of time to devote to i

David Desberg 1.1k Dec 27, 2022
Handle roles and permissions in your Laravel application

Laratrust (Laravel Package) Version Compatibility Laravel Laratrust 8.x 6.x 7.x 6.x 6.x 6.x 5.6.x - 5.8.x 5.2 5.3.x - 5.5.x 5.1 5.0.x - 5.2.x 4.0. Ins

Santiago García 2k Dec 30, 2022
Library to manage HTTP authentication with PHP. Includes ServiceProviders for easy Laravel integration.

Intervention HttpAuth Library to manage HTTP authentication with PHP. Includes ServiceProviders for easy Laravel integration. Installation You can ins

null 69 Jul 14, 2022
EvaOAuth provides a standard interface for OAuth1.0(a) / OAuth2.0 client authorization, it is easy to integrate with any PHP project by very few lines code.

EvaOAuth EvaOAuth provides a standard interface for OAuth1.0 / OAuth2.0 client authorization, it is easy to integrate with any PHP project by very few

AlloVince 256 Nov 16, 2022