Giter Site home page Giter Site logo

magiclabs / magic-admin-php Goto Github PK

View Code? Open in Web Editor NEW
18.0 20.0 6.0 161 KB

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

Home Page: https://docs.magic.link/admin-sdk/php

License: MIT License

PHP 99.78% Makefile 0.22%
php identity authentication passwordless

magic-admin-php's People

Contributors

ayv8er avatar brianrlewis avatar fyjen avatar itprodev avatar justinnout avatar magic-ravi avatar szepeviktor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magic-admin-php's Issues

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

โœ… Prerequisites

  • Did you perform a cursory search of open issues? Is this bug already reported elsewhere?
  • Are you running the latest SDK version?
  • 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

Include provenance and more to user meta data

โœ… Prerequisites

  • Did you perform a cursory search of open issues? Is this feature already requested elsewhere?
  • 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],
        ...
    },
    ...
}

PHP LOGIN support

โœ… Prerequisites

  • Did you perform a cursory search of open issues? Is this question already asked elsewhere?
  • Are you reporting to the correct repository (magic-admin-php)?

โ“ Question

So, is there a way to actually LOG the user into via a request from the frontend? If the user is only logging in via the CLIENT side, then any information generated by that login wouldn't be trusted on the BACKEND - even if you hooked into the 'ready' state - as if you have to send a request to the backend to CHECK if the user is logged in, then, that can be spoofed by even a 3rd grader.

Normally, I'd expect the process to work like:

  • user is on login page
  • user enters email
  • user clicks login
  • ajax request sends email to backend
  • backend generates a unique signing code/link to give to the user
  • system redirects user to that link
  • user logs in
  • webhook triggers proving user logged in by passing the needed information (email and did) back to the server side without any user or client side interactions
  • frontend waits for confirmation that the user has successfully logged in (simple polling can do this)
  • once confirmed in db that they are logged in, takes the user to the homepage of the app

However, it doesn't appear that magic supports any webhooks for PHP or true server side applications.

So, how can one actually IMPLEMENT this if their application is PHP based (and not laravel/symfony based), as nothing that is sent from the CLIENT side can be trusted?

๐ŸŒŽ Environment

Software Version(s)
magic-admin-php latest
php 8.1
Operating System ubuntu 20.04

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.