Giter Site home page Giter Site logo

magiclabs / magic-admin-ruby Goto Github PK

View Code? Open in Web Editor NEW
10.0 17.0 5.0 419 KB

Magic admin Ruby 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/ruby

License: MIT License

Ruby 100.00%
ruby identity authentication passwordless

magic-admin-ruby's Introduction

Magic Admin Ruby SDK

The Magic Admin Ruby 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

Add this line to your application's Gemfile:

gem 'magic-admin'

And then execute:

$ bundle

Or install it yourself as:

$ gem install magic-admin

Prerequisites

  • Ruby 2.5+

Quick Start

Before you start, you will need an API secret key. You can get one from the Magic Dashboard. Once you have the API secret key, you can instantiate a Magic object.

require 'magic-admin'

magic = Magic.new(api_secret_key: '<YOUR_API_SECRET_KEY>')

magic.token.validate('DID_TOKEN')

# Read the docs to learn more! ๐Ÿš€

Optionally if you would like, you can load the API secret key from the environment variable, MAGIC_API_SECRET_KEY.

# Set the env variable `MAGIC_API_SECRET_KEY`.

magic = Magic.new

Note: The arguments passed to the Magic object takes precedence over the environment variables.

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 = Magic.new(retries: 5, timeout: 10, backoff: 0.03)

Changelog

See Changelog

License

See License

magic-admin-ruby's People

Contributors

fyjen avatar justinnout avatar magic-ravi avatar nitinvupk avatar q9f avatar smithki avatar

Stargazers

 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

magic-admin-ruby's Issues

Ruby 3 Support

โœ… 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-ruby)?

โœจ Feature Request

Hi, i was hoping to be able to use Magic in a new Rails 7 app with Ruby 3, however it appears the dependencies of this gem require Ruby (~> 2.2) and so i get an error when running bundle install.

๐Ÿงฉ Context

Here's my Gemfile

gem "magic-admin", ">= 0.1.2"

Output after running bin/bundle install

Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 3.0.2.0)

    magic-admin (>= 0.1.2) was resolved to 0.1.2, which depends on
      eth (~> 0.4) was resolved to 0.4.0, which depends on
        ethereum-base (~> 0.1.4) was resolved to 0.1.4, which depends on
          digest-sha3 (~> 1.1) was resolved to 1.1.0, which depends on
            Ruby (~> 2.2)

๐Ÿ’ป Examples

[Do you have any example(s) for the requested feature? If so, describe/demonstrate your example(s) here.]

Signature error after gem update

โœ… Prerequisites

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

๐Ÿ› Description

After upgrading to the 0.1.3 version I got the error: "Signature mismatch between 'proof' and 'claim'. (MagicAdmin::DIDTokenError)"

๐Ÿงฉ Steps to Reproduce

It happens when you try to validate the token.

๐Ÿค” Expected behavior

Validate the token properly.

๐Ÿ˜ฎ Actual behavior

(...)/.rvm/gems/ruby-3.1.1/gems/magic-admin-0.1.3/lib/magic-admin/resource/token.rb:123:in `validate_public_address!': Signature mismatch between 'proof' and 'claim'. (MagicAdmin::DIDTokenError)
	from (...)/.rvm/gems/ruby-3.1.1/gems/magic-admin-0.1.3/lib/magic-admin/resource/token.rb:25:in `validate'

๐Ÿ’ป Code Sample

require 'magic-admin'

magic = Magic.new(api_secret_key: 'secret key')
did_token = 'valid token'
magic.token.validate(did_token)

๐ŸŒŽ Environment

Software Version(s)
magic-admin-ruby 0.1.3
ruby 3.1.1
rails 7.0.2.3

`signature length 16!` exception after upgrading from 0.1.2 to 0.1.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-ruby)?

๐Ÿ› Description

I upgraded to the latest version and now I get signature length 16! when doing MAGIC.token.validate. So all my tests fail and the app no longer works.

๐Ÿงฉ Steps to Reproduce

  1. Upgrade from 0.1.2 to 0.1.4
  2. [Second Step]
  3. [and so on...]

๐Ÿค” Expected behavior

Should work as before.

๐Ÿ˜ฎ Actual behavior

Validating a token raises the Exception:Unknown signature length 16! exception

๐Ÿ’ป Code Sample

[If possible, please provide a code repository, gist, code snippet or sample files to reproduce the issue.]

๐ŸŒŽ Environment

Software Version(s)
magic-admin-ruby 0.1.4
ruby
Operating System both macOS Ventura and Linux

Thanks in advance for your help.

User actions fail if Etc.getlogin() returns nil

โœ… 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-ruby)?

๐Ÿ› Description

In config.rb, the user_name function has no error checking on the result of Etc.getlogin(). ๏ปฟIf Etc.getlogin() returns nil, the function throws an exception, which prevents any of the user.get_metadata_by_* functions from succeeding.

๐Ÿงฉ Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [and so on...]

๐Ÿค” Expected behavior

[What you expected to happen?]

๐Ÿ˜ฎ Actual behavior

irb(main):006:0> resp = magic.user.get_metadata_by_token(token)
Traceback (most recent call last):
       16: from railties (5.2.4.4) lib/rails/command.rb:46:in `invoke'
       15: from railties (5.2.4.4) lib/rails/command/base.rb:69:in `perform'
       14: from thor (0.20.3) lib/thor.rb:387:in `dispatch'
       13: from thor (0.20.3) lib/thor/invocation.rb:126:in `invoke_command'
       12: from thor (0.20.3) lib/thor/command.rb:27:in `run'
       11: from railties (5.2.4.4) lib/rails/commands/console/console_command.rb:96:in `perform'
       10: from railties (5.2.4.4) lib/rails/commands/console/console_command.rb:19:in `start'
        9: from railties (5.2.4.4) lib/rails/commands/console/console_command.rb:64:in `start'
        8: from (irb):6
        7: from magic-admin (0.1.1) lib/magic-admin/resource/user.rb:73:in `get_metadata_by_token'
        6: from magic-admin (0.1.1) lib/magic-admin/resource/user.rb:41:in `get_metadata_by_issuer'
        5: from magic-admin (0.1.1) lib/magic-admin/util.rb:56:in `headers'
        4: from magic-admin (0.1.1) lib/magic-admin/util.rb:37:in `user_agent'
        3: from magic-admin (0.1.1) lib/magic-admin/util.rb:21:in `platform_info'
        2: from magic-admin (0.1.1) lib/magic-admin/config.rb:40:in `user_name'
        1: from magic-admin (0.1.1) lib/magic-admin/config.rb:40:in `getpwnam'
TypeError (no implicit conversion of nil into String)

๐Ÿ’ป Code Sample

[If possible, please provide a code repository, gist, code snippet or sample files to reproduce the issue.]

๐ŸŒŽ Environment

Software Version(s)
magic-admin-ruby
ruby
Operating System

installed gem causes rails to hang, possible segfault?

I installed Magic yesterday but the ruby gem causes Rails to hang.

When running rails c the process hangs, with no error or output until killed.

gem 0.1.2
ruby 2.6.5p114
Rails 5.2.4.4

It appears to segfault when loading it's dependency eth, which loads money-tree, which dies on this line: https://github.com/GemHQ/money-tree/blob/master/lib/openssl_extensions.rb#L9

This might be related to this issue: ffi/ffi#634 . My guess is it's caused by the ruby version.

I downloaded this gem and tried to load the lib files, and got an Abort in the terminal. I did this for each gem until I found the culprit line.

DID token validation causes NameError

โœ… Prerequisites

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

๐Ÿ› Description

Reference to the Eth gem causes NameError on Eth::Utils call. The name has been changed to Eth::Util in the Eth 0.5

๐Ÿงฉ Steps to Reproduce

It happens on the DID token validation

๐Ÿค” Expected behavior

Not to get the NameError

๐Ÿ˜ฎ Actual behavior

.../gems/ruby-3.1.1/gems/magic-admin-0.1.2/lib/magic-admin/resource/token.rb:104:in `rec_pub_address': uninitialized constant Eth::Utils (NameError)
                                            
        Eth::Utils.public_key_to_address personal_recover(claim, proof)
           ^^^^^^^                                                        

๐Ÿ’ป Code Sample

# Gemfile

gem 'magic-admin'


# Code that causes error

magic = Magic.new(api_secret_key: 'secret key')
did_token = 'the DID token from Authorization header'
magic.token.validate(did_token)

๐ŸŒŽ Environment

Software Version(s)
magic-admin-ruby 0.1.2
ruby 3.1.1
rails 7.0.2.23
bundler 2.3.7
Operating System

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.