streem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5f56ca936fa92efe7d634be3dcbb540c6922cff39761ba9089248e06f53fad64
4
+ data.tar.gz: ed959b2683c58b9e009c4c633ceb012f9271ba66a74e30237b0f2a469daba410
5
+ SHA512:
6
+ metadata.gz: ae9f107eb9581b9989bfe24a0bdd10b8c433f0c078c5b907c647faa9c6eac22b55b77c7886e74b1d4be39335337e0c43d9c3725ff57e09b3f043c99981186aee
7
+ data.tar.gz: 2b9a6614017ef7569d28e700e9f970e3c05ed708030b01f73063f3a9e10bfeb2e73bf5b77a927a4c75f75b0d8116ab6d619a040d8fa719f9f8f0cc45b32ce647
data/src/streem.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Provides access to the Streem SDK. Start by calling Streem.init() with your API Key ID and Secret
4
+ class Streem
5
+ VERSION = "0.1.0"
6
+ @api_key_id = nil
7
+ @api_key_secret = nil
8
+ @api_environment = "prod-us"
9
+
10
+ # Define static-like behavior using the metaclass. This allows auto-generation of the accessor methods,
11
+ # and singleton initialization of the Streem variables.
12
+ class << self
13
+ attr_reader :api_key_id, :api_key_secret
14
+ attr_accessor :api_environment
15
+
16
+ def init(api_key_id, api_key_secret)
17
+ @api_key_id = api_key_id
18
+ @api_key_secret = api_key_secret
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "base64"
4
+ require "jose"
5
+
6
+ class Streem
7
+ # Class for building Streem Tokens. Configure the token using the available setter methods, and finalize the token
8
+ # by calling `builder.token`. This returns a string representation of the token, that can be provided to the client.
9
+ class TokenBuilder
10
+ attr_accessor :user_id, :name, :email, :avatar_url, :expiration_ms, :session_ms
11
+
12
+ def initialize
13
+ @expiration_ms = 60 * 60 * 1000 # one hour
14
+ end
15
+
16
+ # Build the token using the configured attributes. Validation errors may be raised from this method
17
+ def token
18
+ validate_token
19
+
20
+ key_as_json = Base64.decode64(Streem.api_key_secret)
21
+ jwk = JOSE::JWK.from(key_as_json)
22
+
23
+ claim = token_claims
24
+
25
+ # noinspection RubyStringKeysInHashInspection
26
+ signed_token = JOSE::JWS.sign(jwk, claim.to_json, { "alg" => "ES256" })
27
+ signed_token.compact
28
+ end
29
+
30
+ private
31
+
32
+ def validate_token
33
+ raise "Must call Streem.init first" if Streem.api_key_id.nil? || Streem.api_key_secret.nil?
34
+ raise "user_id is required" if @user_id.nil?
35
+ end
36
+
37
+ def token_claims
38
+ {
39
+ iss: "streem:api:#{Streem.api_key_id}",
40
+ sub: @user_id,
41
+ exp: (Time.now + @expiration_ms).to_i,
42
+ session_exp: @session_ms.nil? ? nil : (Time.now + @session_ms).to_i,
43
+ iat: Time.now.to_i,
44
+ aud: "https://api.#{Streem.api_environment}.streem.cloud/",
45
+ name: @name,
46
+ email: @email,
47
+ picture: @avatar_url
48
+ }
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: streem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Streem Dev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jose
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.3
27
+ description: Streem library to interact with the Streem API, and generate Embedded
28
+ SSO tokens
29
+ email:
30
+ - dev@streem.pro
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - src/streem.rb
36
+ - src/streem_token_builder.rb
37
+ homepage: https://streem.pro
38
+ licenses: []
39
+ metadata:
40
+ homepage_uri: https://streem.pro
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - src
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.4.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.0.6
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Streem SDK
60
+ test_files: []