amazon_auth 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/.env.sample +3 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +6 -0
- data/amazon_auth.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/convert_login +20 -0
- data/bin/setup +8 -0
- data/lib/amazon_auth/amazon_info.rb +5 -0
- data/lib/amazon_auth/client.rb +75 -0
- data/lib/amazon_auth/converter.rb +18 -0
- data/lib/amazon_auth/version.rb +3 -0
- data/lib/amazon_auth.rb +12 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0f93a64aa935ee1f9aad2016faa128b74a26c72d
|
4
|
+
data.tar.gz: 34a515fb0d726f3a00b07d5011bcb2d07d67c735
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a77af4c224e57ba5c67fc9436ad715799ff2636d78c81872aa61d07d351a569120c293e524cd81c3e5ec8302a5a9e1b24d28efe7f1e58cd56c931afb8d7dcf19
|
7
|
+
data.tar.gz: 2e938e369b4a9c81d8d23398dfdba713d16cbecb8b9c65d3e494d95d7158ba03751ef5b6a0d770d7475e7bda8bc9b52a08846ed27522e14500b3d74ee6b12e32
|
data/.env.sample
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Kazuho Yamaguchi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# AmazonAuth
|
2
|
+
|
3
|
+
Sign In Amazon using Capybara and Selenium
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'amazon_auth'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install amazon_auth
|
20
|
+
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
Firefox (<= 47.0.2)
|
24
|
+
|
25
|
+
This may not work with newer versions of Firefox.
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```
|
30
|
+
cp .env.sample .env
|
31
|
+
vi .env
|
32
|
+
```
|
33
|
+
|
34
|
+
### Set Amazon credentials on your local machine
|
35
|
+
|
36
|
+
[Quick] You can set `AMAZON_USERNAME` and `AMAZON_PASSWORD` in _.env_.
|
37
|
+
|
38
|
+
[Recommended] Or you can convert them to protect them against shoulder surfing.
|
39
|
+
Run `./bin/convert_login` and paste the output to _env_.
|
40
|
+
(`AMAZON_USERNAME_CODE` and `AMAZON_PASSWORD_CODE`)
|
41
|
+
|
42
|
+
You can change the salt with `AMAZON_CODE_SALT` if you like.
|
43
|
+
|
44
|
+
### Run
|
45
|
+
|
46
|
+
```
|
47
|
+
bin/console
|
48
|
+
```
|
49
|
+
|
50
|
+
You can move around pages using Capybara DSL
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
client = AmazonAuth::Client.new
|
54
|
+
page = client.sign_in
|
55
|
+
|
56
|
+
# Continue to the page for Kindle
|
57
|
+
page.first('a', text: 'コンテンツと端末の管理').click
|
58
|
+
|
59
|
+
# Close browser
|
60
|
+
page.driver.quit
|
61
|
+
```
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
Some features come from https://github.com/kyamaguchi/kindle
|
66
|
+
|
67
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
68
|
+
|
69
|
+
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).
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kyamaguchi/amazon_auth.
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
78
|
+
|
data/Rakefile
ADDED
data/amazon_auth.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'amazon_auth/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "amazon_auth"
|
8
|
+
spec.version = AmazonAuth::VERSION
|
9
|
+
spec.authors = ["Kazuho Yamaguchi"]
|
10
|
+
spec.email = ["kzh.yap@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Login amazon.}
|
13
|
+
spec.description = %q{Login amazon.}
|
14
|
+
spec.homepage = "https://github.com/kyamaguchi/amazon_auth"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'capybara'
|
23
|
+
spec.add_runtime_dependency 'selenium-webdriver'
|
24
|
+
spec.add_runtime_dependency 'highline'
|
25
|
+
spec.add_runtime_dependency 'dotenv'
|
26
|
+
spec.add_runtime_dependency 'activesupport'
|
27
|
+
spec.add_development_dependency "bundler"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "amazon_auth"
|
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/convert_login
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative "../lib/amazon_auth"
|
4
|
+
require 'highline/import'
|
5
|
+
|
6
|
+
result = []
|
7
|
+
|
8
|
+
login = if amazon_username = ENV['AMAZON_USERNAME']
|
9
|
+
amazon_username
|
10
|
+
else
|
11
|
+
ask("Enter your #{AmazonInfo.domain} username: ") { |q| q.echo = true } unless login = ARGV[0]
|
12
|
+
end
|
13
|
+
passwd = ENV['AMAZON_PASSWORD'] || ask("Enter your #{AmazonInfo.domain} password: ") { |q| q.echo = "*" }
|
14
|
+
|
15
|
+
raise "Empty login or password" if login.to_s.size == 0 || passwd.to_s.size == 0
|
16
|
+
|
17
|
+
puts "Put the following lines in .env (Remove AMAZON_USERNAME and AMAZON_PASSWORD if you have)"
|
18
|
+
puts
|
19
|
+
puts "AMAZON_USERNAME_CODE=#{AmazonAuth::Converter.encode(login)}"
|
20
|
+
puts "AMAZON_PASSWORD_CODE=#{AmazonAuth::Converter.encode(passwd)}"
|
data/bin/setup
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
module AmazonAuth
|
2
|
+
class Client
|
3
|
+
INITIAL_ENTRY_URL = 'https://www.amazon.co.jp/'
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@url = options.fetch(:url) { INITIAL_ENTRY_URL }
|
7
|
+
@login = options.fetch(:login) do
|
8
|
+
if (amazon_username_code = ENV['AMAZON_USERNAME_CODE']).present?
|
9
|
+
Converter.decode(amazon_username_code)
|
10
|
+
else
|
11
|
+
ENV['AMAZON_USERNAME'].presence || raise('AMAZON_USERNAME is required.')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
@password = options.fetch(:password) do
|
15
|
+
if (amazon_password_code = ENV['AMAZON_PASSWORD_CODE']).present?
|
16
|
+
Converter.decode(amazon_password_code)
|
17
|
+
else
|
18
|
+
ENV['AMAZON_PASSWORD'].presence || raise('AMAZON_PASSWORD is required.')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def sign_in
|
24
|
+
@session = Capybara::Session.new(:selenium)
|
25
|
+
@session.visit @url
|
26
|
+
@session.within('#nav-tools') do
|
27
|
+
@session.click_on 'サインイン'
|
28
|
+
end
|
29
|
+
|
30
|
+
fill_in_with_stroke('ap_email', @login)
|
31
|
+
fill_in_with_stroke('ap_password', @password)
|
32
|
+
@session.click_on('signInSubmit')
|
33
|
+
|
34
|
+
while image_recognition_displayed? do
|
35
|
+
retry_sign_in
|
36
|
+
end
|
37
|
+
|
38
|
+
@session.first('.nav-line-2').click
|
39
|
+
@session
|
40
|
+
end
|
41
|
+
|
42
|
+
def retry_sign_in
|
43
|
+
fill_in_with_stroke('ap_password', @password)
|
44
|
+
input = ask "Got the prompt. Read characters from the image: "
|
45
|
+
fill_in_with_stroke('auth-captcha-guess', input)
|
46
|
+
@session.click_on('signInSubmit')
|
47
|
+
end
|
48
|
+
|
49
|
+
def fill_in_with_stroke(dom_id, value)
|
50
|
+
sleep_s
|
51
|
+
element = @session.first("##{dom_id}")
|
52
|
+
value.split(//u).each do |char|
|
53
|
+
element.send_keys(char)
|
54
|
+
sleep rand
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def image_recognition_displayed?
|
59
|
+
@session.has_content?('お客様のアカウントを強力に保護するため') || @session.has_content?('問題が発生しました')
|
60
|
+
end
|
61
|
+
|
62
|
+
def driver
|
63
|
+
@session.driver
|
64
|
+
end
|
65
|
+
|
66
|
+
def sleep_s(sec = 2)
|
67
|
+
sleep sec
|
68
|
+
end
|
69
|
+
|
70
|
+
# Hide instance variables of credentials on console
|
71
|
+
def inspect
|
72
|
+
to_s
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AmazonAuth
|
2
|
+
class Converter
|
3
|
+
|
4
|
+
def self.encode(str)
|
5
|
+
raise "Empty string" if str.to_s.size == 0
|
6
|
+
Base64.strict_encode64("#{salt}#{str}")
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.decode(code)
|
10
|
+
raise "Empty string" if code.to_s.size == 0
|
11
|
+
Base64.strict_decode64(code).gsub(/\A#{salt}/, '')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.salt
|
15
|
+
ENV['AMAZON_CODE_SALT'] || "iloveamazon"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/amazon_auth.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
Dotenv.load
|
3
|
+
require "active_support/all"
|
4
|
+
require "capybara"
|
5
|
+
require "highline/import"
|
6
|
+
require_relative "amazon_auth/version"
|
7
|
+
require_relative "amazon_auth/amazon_info"
|
8
|
+
require_relative "amazon_auth/converter"
|
9
|
+
require_relative "amazon_auth/client"
|
10
|
+
|
11
|
+
module AmazonAuth
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amazon_auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuho Yamaguchi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: selenium-webdriver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: highline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Login amazon.
|
126
|
+
email:
|
127
|
+
- kzh.yap@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".env.sample"
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- amazon_auth.gemspec
|
141
|
+
- bin/console
|
142
|
+
- bin/convert_login
|
143
|
+
- bin/setup
|
144
|
+
- lib/amazon_auth.rb
|
145
|
+
- lib/amazon_auth/amazon_info.rb
|
146
|
+
- lib/amazon_auth/client.rb
|
147
|
+
- lib/amazon_auth/converter.rb
|
148
|
+
- lib/amazon_auth/version.rb
|
149
|
+
homepage: https://github.com/kyamaguchi/amazon_auth
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.4.8
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: Login amazon.
|
173
|
+
test_files: []
|