diuitauth 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/diuitauth.gemspec +34 -0
- data/lib/diuitauth.rb +84 -0
- data/lib/diuitauth/version.rb +3 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b00ad9b9a9a2531fee1c2a50228873f6eff39279
|
4
|
+
data.tar.gz: 7de90e59566421a9c131e306cdc673c5a7d7dab4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bab513f777396fb4dc56f3dd7f7a4bcb991402afd7a89e6349d6aa2b227790677786ef5bba95dfb32a048e071c8c46a764cd06a78ba4cf53f1633de221fbdb5b
|
7
|
+
data.tar.gz: 8dcc9812087ba30115159de38786720a26598ac88880d7641e9327d10c42dcd9b09828398850ec046e815e5c651e429167d2a489de5d6e28d67fb64f4daa4eb9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Diuitauth
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/diuitauth`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'diuitauth'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install diuitauth
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/diuitauth.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "diuitauth"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/diuitauth.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'diuitauth/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "diuitauth"
|
8
|
+
spec.version = Diuitauth::VERSION
|
9
|
+
spec.authors = ["Cyril Yu"]
|
10
|
+
spec.email = ["cyrilyu@diuit.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Diuit API Login libs}
|
13
|
+
spec.description = %q{Get Session Token}
|
14
|
+
spec.homepage = "http://api.diuit.com"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "jwt", "~> 1.5.3"
|
32
|
+
spec.add_development_dependency "json", "~> 1.8.3"
|
33
|
+
spec.add_development_dependency "rest-client", "~> 1.8.0"
|
34
|
+
end
|
data/lib/diuitauth.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require "diuitauth/version"
|
2
|
+
require 'rest-client'
|
3
|
+
require 'jwt'
|
4
|
+
|
5
|
+
module Diuitauth
|
6
|
+
# Your code goes here...
|
7
|
+
class Login
|
8
|
+
def self.get_session_token(client)
|
9
|
+
begin
|
10
|
+
JSON.parse(client)
|
11
|
+
rescue JSON::ParserError => e
|
12
|
+
return "Invalid JSON format"
|
13
|
+
end
|
14
|
+
|
15
|
+
params = [
|
16
|
+
"app_id",
|
17
|
+
"app_key",
|
18
|
+
"key_id",
|
19
|
+
"private_key",
|
20
|
+
"exp",
|
21
|
+
"platform",
|
22
|
+
"user_serial",
|
23
|
+
"device_id"
|
24
|
+
]
|
25
|
+
|
26
|
+
# check json data is enough or not
|
27
|
+
params.each do |p|
|
28
|
+
unless (JSON.parse(client)).has_key?(p)
|
29
|
+
return "can not find #{p}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
clientJSON = JSON.parse(client)
|
34
|
+
app_id = clientJSON["app_id"]
|
35
|
+
app_key = clientJSON["app_key"]
|
36
|
+
kid = clientJSON["key_id"]
|
37
|
+
private_key = clientJSON["private_key"]
|
38
|
+
exp = clientJSON["exp"].to_i
|
39
|
+
platform = clientJSON["platform"]
|
40
|
+
sub = clientJSON["user_serial"]
|
41
|
+
device_id = clientJSON["device_id"]
|
42
|
+
|
43
|
+
header = {
|
44
|
+
'x-diuit-application-id' => app_id,
|
45
|
+
'x-diuit-app-key' => app_key
|
46
|
+
}
|
47
|
+
res = RestClient.get('https://api.diuit.net/1/auth/nonce', header)
|
48
|
+
nonce = (JSON.parse(res))["nonce"]
|
49
|
+
jwt_header = {
|
50
|
+
"typ" => 'JWT',
|
51
|
+
"alg" => 'RS256',
|
52
|
+
"cty" => "diuit-auth;v=1",
|
53
|
+
"kid" => kid
|
54
|
+
}
|
55
|
+
|
56
|
+
jwt_payload = {
|
57
|
+
"exp" => Time.at(exp).utc.iso8601,
|
58
|
+
"iss" => app_id,
|
59
|
+
"iat" => Time.now.utc.iso8601,
|
60
|
+
"sub" => sub,
|
61
|
+
"nonce" => nonce
|
62
|
+
}
|
63
|
+
|
64
|
+
token = JWT.encode jwt_payload, private_key, 'none', jwt_header
|
65
|
+
|
66
|
+
request_data = {
|
67
|
+
'jwt' => token,
|
68
|
+
'deviceId' => device_id,
|
69
|
+
'platform' => platform
|
70
|
+
}
|
71
|
+
request_headers = {
|
72
|
+
'x-diuit-application-id' => app_id,
|
73
|
+
'x-diuit-app-key' => app_key,
|
74
|
+
'Content-Type' => 'application/json'
|
75
|
+
}
|
76
|
+
|
77
|
+
return RestClient.post 'https://api.diuit.net/1/auth/login', request_data, request_headers
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.Test
|
81
|
+
puts "Test"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: diuitauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cyril Yu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jwt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.5.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.5.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.8.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.8.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.8.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.8.0
|
83
|
+
description: Get Session Token
|
84
|
+
email:
|
85
|
+
- cyrilyu@diuit.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- bin/console
|
95
|
+
- bin/setup
|
96
|
+
- diuitauth.gemspec
|
97
|
+
- lib/diuitauth.rb
|
98
|
+
- lib/diuitauth/version.rb
|
99
|
+
homepage: http://api.diuit.com
|
100
|
+
licenses: []
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.4.6
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Diuit API Login libs
|
122
|
+
test_files: []
|