Class: ReplIdentity::Identity

Inherits:
Object
  • Object
show all
Defined in:
lib/repl_identity/identity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Identity

Returns a new instance of Identity.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/repl_identity/identity.rb', line 5

def initialize(token)
    stdout, status = Open3.capture2(
        REPLIT_CLI_PATH, "identity", "verify",
        "-audience=#{REPL_ID}",
        "-token=#{token}",
        "-json"
    )
    print "\r" + "\e[A\e[K" unless status.success? # Remove error message from replit process

    identity = status.success? ? JSON.parse(stdout) : {}

    @success        = status.success?            
    @audience       = identity["aud"]
    @repl_slug      = identity["slug"]
    @username       = identity["user"]
    @repl_id        = identity["replid"]
    @origin         = identity["origin"]
    @ephemeral      = identity["ephemeral"]
    @origin_repl_id = identity["originReplid"]
end

Instance Attribute Details

#audienceObject (readonly)

Returns the value of attribute audience.



3
4
5
# File 'lib/repl_identity/identity.rb', line 3

def audience
  @audience
end

#ephemeralObject (readonly)

Returns the value of attribute ephemeral.



3
4
5
# File 'lib/repl_identity/identity.rb', line 3

def ephemeral
  @ephemeral
end

#originObject (readonly)

Returns the value of attribute origin.



3
4
5
# File 'lib/repl_identity/identity.rb', line 3

def origin
  @origin
end

#origin_repl_idObject (readonly)

Returns the value of attribute origin_repl_id.



3
4
5
# File 'lib/repl_identity/identity.rb', line 3

def origin_repl_id
  @origin_repl_id
end

#repl_idObject (readonly)

Returns the value of attribute repl_id.



3
4
5
# File 'lib/repl_identity/identity.rb', line 3

def repl_id
  @repl_id
end

#repl_slugObject (readonly)

Returns the value of attribute repl_slug.



3
4
5
# File 'lib/repl_identity/identity.rb', line 3

def repl_slug
  @repl_slug
end

#usernameObject (readonly)

Returns the value of attribute username.



3
4
5
# File 'lib/repl_identity/identity.rb', line 3

def username
  @username
end

Instance Method Details

#verified?(client_repl_id) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/repl_identity/identity.rb', line 26

def verified?(client_repl_id)
    @success &&
        [@repl_id, @origin_repl_id].include?(client_repl_id) &&
        @audience == REPL_ID
end