intercom-app 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +12 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CHANGELOG +7 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +148 -0
- data/LICENSE +19 -0
- data/README.md +109 -0
- data/RELEASING +14 -0
- data/Rakefile +6 -0
- data/app/controllers/intercom_app/authenticated_controller.rb +7 -0
- data/app/controllers/intercom_app/sessions_controller.rb +5 -0
- data/app/models/intercom-app/app.rb +6 -0
- data/app/views/intercom_app/sessions/callback.html.erb +15 -0
- data/config/routes.rb +7 -0
- data/intercom-app.gemspec +29 -0
- data/lib/generators/intercom_app/app_model/app_model_generator.rb +41 -0
- data/lib/generators/intercom_app/app_model/templates/app.rb +4 -0
- data/lib/generators/intercom_app/app_model/templates/apps.yml +3 -0
- data/lib/generators/intercom_app/app_model/templates/db/migrate/create_apps.rb +15 -0
- data/lib/generators/intercom_app/app_model/templates/intercom_session_repository.rb +7 -0
- data/lib/generators/intercom_app/controllers/controllers_generator.rb +29 -0
- data/lib/generators/intercom_app/home_controller/home_controller_generator.rb +22 -0
- data/lib/generators/intercom_app/home_controller/templates/home_controller.rb +6 -0
- data/lib/generators/intercom_app/home_controller/templates/index.html.erb +28 -0
- data/lib/generators/intercom_app/install/install_generator.rb +53 -0
- data/lib/generators/intercom_app/install/templates/intercom_app.rb +5 -0
- data/lib/generators/intercom_app/install/templates/intercom_provider.rb +3 -0
- data/lib/generators/intercom_app/install/templates/intercom_session_repository.rb +1 -0
- data/lib/generators/intercom_app/install/templates/omniauth.rb +2 -0
- data/lib/generators/intercom_app/intercom_app_generator.rb +16 -0
- data/lib/intercom-app/app.rb +10 -0
- data/lib/intercom-app/configuration.rb +23 -0
- data/lib/intercom-app/engine.rb +6 -0
- data/lib/intercom-app/in_memory_session_store.rb +25 -0
- data/lib/intercom-app/login_protection.rb +74 -0
- data/lib/intercom-app/session_repository.rb +34 -0
- data/lib/intercom-app/session_storage.rb +25 -0
- data/lib/intercom-app/sessions_concern.rb +35 -0
- data/lib/intercom-app/version.rb +3 -0
- metadata +42 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1efe773248ef9439365870c93fc8eeb6157004f
|
4
|
+
data.tar.gz: e3ded3e1132f4cbca3bf40c086f78fea84ccce7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61d69c7a3937c84d1f1647865eb1534e60eba03a64aedc40a6e678a4cafac329c582e2871f6acbc0fee0b129fd3271e2c6cbb73e220ba3d2b22d745c343e85d1
|
7
|
+
data.tar.gz: d46307ce2dfa7d65080bf5d900a2a1ca95faed0826d1f7e947fa5514655937ad884bedf91d9a90db23d2a5cb3c12ed8355f26358af669c078bd7e473d4695d73
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Please use the following template to submit your issue. Following this template will allow us to quickly investigate and help you with your issue. Please be aware that issues which do not conform to this template may be closed.
|
2
|
+
|
3
|
+
## Expected behavior
|
4
|
+
|
5
|
+
## Actual behavior
|
6
|
+
|
7
|
+
## Steps to reproduce
|
8
|
+
1.
|
9
|
+
2.
|
10
|
+
3.
|
11
|
+
|
12
|
+
## Logs
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
intercom-app (0.1.0)
|
5
|
+
intercom (~> 3.5)
|
6
|
+
omniauth-intercom (~> 0.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.2.6)
|
12
|
+
actionpack (= 4.2.6)
|
13
|
+
actionview (= 4.2.6)
|
14
|
+
activejob (= 4.2.6)
|
15
|
+
mail (~> 2.5, >= 2.5.4)
|
16
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
17
|
+
actionpack (4.2.6)
|
18
|
+
actionview (= 4.2.6)
|
19
|
+
activesupport (= 4.2.6)
|
20
|
+
rack (~> 1.6)
|
21
|
+
rack-test (~> 0.6.2)
|
22
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
24
|
+
actionview (4.2.6)
|
25
|
+
activesupport (= 4.2.6)
|
26
|
+
builder (~> 3.1)
|
27
|
+
erubis (~> 2.7.0)
|
28
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
29
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
30
|
+
activejob (4.2.6)
|
31
|
+
activesupport (= 4.2.6)
|
32
|
+
globalid (>= 0.3.0)
|
33
|
+
activemodel (4.2.6)
|
34
|
+
activesupport (= 4.2.6)
|
35
|
+
builder (~> 3.1)
|
36
|
+
activerecord (4.2.6)
|
37
|
+
activemodel (= 4.2.6)
|
38
|
+
activesupport (= 4.2.6)
|
39
|
+
arel (~> 6.0)
|
40
|
+
activesupport (4.2.6)
|
41
|
+
i18n (~> 0.7)
|
42
|
+
json (~> 1.7, >= 1.7.7)
|
43
|
+
minitest (~> 5.1)
|
44
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
45
|
+
tzinfo (~> 1.1)
|
46
|
+
arel (6.0.3)
|
47
|
+
builder (3.2.2)
|
48
|
+
byebug (9.0.5)
|
49
|
+
concurrent-ruby (1.0.2)
|
50
|
+
erubis (2.7.0)
|
51
|
+
faraday (0.9.2)
|
52
|
+
multipart-post (>= 1.2, < 3)
|
53
|
+
globalid (0.3.6)
|
54
|
+
activesupport (>= 4.1.0)
|
55
|
+
hashie (3.4.4)
|
56
|
+
i18n (0.7.0)
|
57
|
+
intercom (3.5.1)
|
58
|
+
json (~> 1.8)
|
59
|
+
json (1.8.3)
|
60
|
+
jwt (1.5.4)
|
61
|
+
loofah (2.0.3)
|
62
|
+
nokogiri (>= 1.5.9)
|
63
|
+
mail (2.6.4)
|
64
|
+
mime-types (>= 1.16, < 4)
|
65
|
+
metaclass (0.0.4)
|
66
|
+
mime-types (3.1)
|
67
|
+
mime-types-data (~> 3.2015)
|
68
|
+
mime-types-data (3.2016.0521)
|
69
|
+
mini_portile2 (2.1.0)
|
70
|
+
minitest (5.9.0)
|
71
|
+
mocha (1.1.0)
|
72
|
+
metaclass (~> 0.0.1)
|
73
|
+
multi_json (1.12.1)
|
74
|
+
multi_xml (0.5.5)
|
75
|
+
multipart-post (2.0.0)
|
76
|
+
nokogiri (1.6.8)
|
77
|
+
mini_portile2 (~> 2.1.0)
|
78
|
+
pkg-config (~> 1.1.7)
|
79
|
+
oauth2 (1.2.0)
|
80
|
+
faraday (>= 0.8, < 0.10)
|
81
|
+
jwt (~> 1.0)
|
82
|
+
multi_json (~> 1.3)
|
83
|
+
multi_xml (~> 0.5)
|
84
|
+
rack (>= 1.2, < 3)
|
85
|
+
omniauth (1.3.1)
|
86
|
+
hashie (>= 1.2, < 4)
|
87
|
+
rack (>= 1.0, < 3)
|
88
|
+
omniauth-intercom (0.1.2)
|
89
|
+
omniauth-oauth2 (~> 1.2)
|
90
|
+
omniauth-oauth2 (1.4.0)
|
91
|
+
oauth2 (~> 1.0)
|
92
|
+
omniauth (~> 1.2)
|
93
|
+
pkg-config (1.1.7)
|
94
|
+
rack (1.6.4)
|
95
|
+
rack-test (0.6.3)
|
96
|
+
rack (>= 1.0)
|
97
|
+
rails (4.2.6)
|
98
|
+
actionmailer (= 4.2.6)
|
99
|
+
actionpack (= 4.2.6)
|
100
|
+
actionview (= 4.2.6)
|
101
|
+
activejob (= 4.2.6)
|
102
|
+
activemodel (= 4.2.6)
|
103
|
+
activerecord (= 4.2.6)
|
104
|
+
activesupport (= 4.2.6)
|
105
|
+
bundler (>= 1.3.0, < 2.0)
|
106
|
+
railties (= 4.2.6)
|
107
|
+
sprockets-rails
|
108
|
+
rails-deprecated_sanitizer (1.0.3)
|
109
|
+
activesupport (>= 4.2.0.alpha)
|
110
|
+
rails-dom-testing (1.0.7)
|
111
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
112
|
+
nokogiri (~> 1.6.0)
|
113
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
114
|
+
rails-html-sanitizer (1.0.3)
|
115
|
+
loofah (~> 2.0)
|
116
|
+
railties (4.2.6)
|
117
|
+
actionpack (= 4.2.6)
|
118
|
+
activesupport (= 4.2.6)
|
119
|
+
rake (>= 0.8.7)
|
120
|
+
thor (>= 0.18.1, < 2.0)
|
121
|
+
rake (10.5.0)
|
122
|
+
sprockets (3.6.3)
|
123
|
+
concurrent-ruby (~> 1.0)
|
124
|
+
rack (> 1, < 3)
|
125
|
+
sprockets-rails (3.1.1)
|
126
|
+
actionpack (>= 4.0)
|
127
|
+
activesupport (>= 4.0)
|
128
|
+
sprockets (>= 3.0.0)
|
129
|
+
sqlite3 (1.3.11)
|
130
|
+
thor (0.19.1)
|
131
|
+
thread_safe (0.3.5)
|
132
|
+
tzinfo (1.2.2)
|
133
|
+
thread_safe (~> 0.1)
|
134
|
+
|
135
|
+
PLATFORMS
|
136
|
+
ruby
|
137
|
+
|
138
|
+
DEPENDENCIES
|
139
|
+
bundler (~> 1.12)
|
140
|
+
byebug
|
141
|
+
intercom-app!
|
142
|
+
mocha
|
143
|
+
rails (~> 4.2.6)
|
144
|
+
rake (~> 10.0)
|
145
|
+
sqlite3
|
146
|
+
|
147
|
+
BUNDLED WITH
|
148
|
+
1.12.5
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2016 Intercom
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
Intercom App
|
2
|
+
===========
|
3
|
+
|
4
|
+
Intercom Application Rails engine and generator
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
This gem includes a Rails Engine and generators for writing Rails applications using the Intercom API. The Engine provides a SessionsController and all the required code for authenticating with an app via Oauth.
|
9
|
+
|
10
|
+
Apply to become an Intercom Developer
|
11
|
+
--------------------------------
|
12
|
+
To create an Intercom application and get your `app_key` and `app_secret` you will need to create an [Intercom application](https://app.intercom.io) first.
|
13
|
+
Once your application is created you can apply for an oauth application in the "App Settings >> Oauth" section.
|
14
|
+
|
15
|
+
Installation
|
16
|
+
------------
|
17
|
+
To get started create a new rails app :
|
18
|
+
|
19
|
+
``` sh
|
20
|
+
# Create a new rails app
|
21
|
+
$ rails new my_intercom_app
|
22
|
+
$ cd my_intercom_app
|
23
|
+
```
|
24
|
+
Then add `intercom-app` to your Gemfile and bundle install :
|
25
|
+
`gem 'intercom-app'`
|
26
|
+
and run :
|
27
|
+
``` sh
|
28
|
+
$ bundle install
|
29
|
+
```
|
30
|
+
|
31
|
+
Now we are ready to run any of the intercom_app generators. The following section explains the generators and what they can do.
|
32
|
+
|
33
|
+
|
34
|
+
Generators
|
35
|
+
----------
|
36
|
+
|
37
|
+
### Default Generator
|
38
|
+
|
39
|
+
The default generator will run the `install`, `app_model`, and `home_controller` generators. This is the recommended way to start your app.
|
40
|
+
|
41
|
+
```sh
|
42
|
+
$ rails generate intercom_app --app_key <your_app_key> --app_secret <your_app_secret> --oauth_modal true
|
43
|
+
```
|
44
|
+
**oauth_modal**:
|
45
|
+
- If true you can authenticate with Intercom using a modal
|
46
|
+
- If false you can authenticate with Intercom directly from the current tab
|
47
|
+
|
48
|
+
|
49
|
+
### Install Generator
|
50
|
+
|
51
|
+
```sh
|
52
|
+
$ rails generate intercom_app:install
|
53
|
+
|
54
|
+
# or optionally with arguments:
|
55
|
+
|
56
|
+
$ rails generate intercom_app:install --app_key <your_app_key> --secret <your_app_secret> --oauth_modal true
|
57
|
+
```
|
58
|
+
|
59
|
+
You can update any of these settings later on easily, the arguments are simply for convenience.
|
60
|
+
|
61
|
+
The generator adds IntercomApp and the required initializers to the host Rails application.
|
62
|
+
|
63
|
+
After running the `install` generator, you can start your app with `bundle exec rails server` and install your app by visiting localhost.
|
64
|
+
|
65
|
+
|
66
|
+
### App Model Generator
|
67
|
+
|
68
|
+
```sh
|
69
|
+
$ rails generate intercom_app:app_model
|
70
|
+
```
|
71
|
+
|
72
|
+
The install generator doesn't create any database models for you and if you are starting a new app its quite likely that you will want one (most of our internally developed apps do!). This generator creates a simple app model and a migration. It also creates a model called `SessionStorage` which interacts with `IntercomApp::SessionRepository`. Check out the later section to learn more about `IntercomApp::SessionRepository`
|
73
|
+
|
74
|
+
*Note that you will need to run rake db:migrate after this generator*
|
75
|
+
|
76
|
+
|
77
|
+
### Home Controller Generator
|
78
|
+
|
79
|
+
```sh
|
80
|
+
$ rails generate intercom_app:home_controller
|
81
|
+
```
|
82
|
+
|
83
|
+
This generator creates an example home controller that is retrieving your user list and displays your users names.
|
84
|
+
|
85
|
+
|
86
|
+
### Controllers, Routes and Views
|
87
|
+
|
88
|
+
The last group of generators are for your convenience if you want to start overriding code included as part of the Rails engine. For example by default the engine provides a simple SessionController, if you run the `rails generate intercom_app:controllers` generator then this code gets copied out into your app so you can start adding to it. Routes and views follow the exact same pattern.
|
89
|
+
|
90
|
+
|
91
|
+
Managing App Keys and Secrets
|
92
|
+
-----------------
|
93
|
+
|
94
|
+
The `install` generator places your App credentials directly into the intercom_app initializer which is convenient and fine for development but once your app goes into production **your api credentials should not be in source control**. When we develop apps we keep our keys in environment variables so a production intercom_app initializer would look like this:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
IntercomApp.configure do |config|
|
98
|
+
config.api_key = ENV['INTERCOM_CLIENT_APP_KEY']
|
99
|
+
config.secret = ENV['INTERCOM_CLIENT_APP_SECRET']
|
100
|
+
config.oauth_modal = false
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
Connect to the Intercom API
|
105
|
+
----------------------
|
106
|
+
This gem includes the following libraries :
|
107
|
+
|
108
|
+
http://github.com/intercom/omniauth-intercom <= Simple rake middleware to authenticate your customers with Intercom
|
109
|
+
http://github.com/intercom/intercom-ruby <= Intercom Ruby API wrapper
|
data/RELEASING
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
To release a new version of the intercom-ruby-app gem :
|
2
|
+
1. Update the version number in `intercom-ruby-app/lib/intercom-ruby-app.rb`
|
3
|
+
2. Add a CHANGELOG entry
|
4
|
+
3. Commit to master with an explicit message : "Bump to vX.Y.Z"
|
5
|
+
4. Tag the new release :
|
6
|
+
$ git tag VX.Y.Z
|
7
|
+
5. Push the new release :
|
8
|
+
$ git push
|
9
|
+
6. Push the new tag :
|
10
|
+
$ git push --tags
|
11
|
+
7. Build the new gem :
|
12
|
+
$ gem build intercom-ruby-app.gemspec
|
13
|
+
8. Push the new gem :
|
14
|
+
$ gem push intercom-ruby-app-X.Y.Z.gem
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Authorized</title>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
<script type="text/javascript">
|
7
|
+
setTimeout(function() {
|
8
|
+
if (window.opener) {
|
9
|
+
window.opener.oauth_success = true;
|
10
|
+
}
|
11
|
+
window.close();
|
12
|
+
}, 1000);
|
13
|
+
</script>
|
14
|
+
</body>
|
15
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'intercom-app/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'intercom-app'
|
7
|
+
s.version = IntercomApp::VERSION
|
8
|
+
s.date = '2016-07-04'
|
9
|
+
s.summary = "Intercom.io ruby application boilerplate"
|
10
|
+
s.description = "This gem helps you to get started with your Intercom.io app"
|
11
|
+
s.authors = ["Kevin Antoine"]
|
12
|
+
s.email = 'kevin.antoine@intercom.io'
|
13
|
+
s.files = ["lib/intercom-app.rb"]
|
14
|
+
s.homepage =
|
15
|
+
'http://rubygems.org/gems/intercom-ruby-app'
|
16
|
+
s.license = 'MIT'
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
|
20
|
+
s.add_runtime_dependency 'intercom', '~>3.5'
|
21
|
+
s.add_runtime_dependency 'omniauth-intercom', '~>0.1'
|
22
|
+
|
23
|
+
s.add_development_dependency 'rails', '~> 4.2'
|
24
|
+
s.add_development_dependency 'sqlite3', '~> 0'
|
25
|
+
s.add_development_dependency 'mocha', '~> 0'
|
26
|
+
s.add_development_dependency 'byebug', '~> 0'
|
27
|
+
s.add_development_dependency 'bundler', '~> 1.12'
|
28
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module IntercomApp
|
4
|
+
module Generators
|
5
|
+
class AppModelGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def create_app_model
|
10
|
+
copy_file 'app.rb', 'app/models/app.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_app_migration
|
14
|
+
copy_migration 'create_apps.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_session_storage_initializer
|
18
|
+
copy_file 'intercom_session_repository.rb', 'config/initializers/intercom_session_repository.rb', force: true
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_app_fixtures
|
22
|
+
copy_file 'apps.yml', 'test/fixtures/apps.yml'
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def copy_migration(migration_name, config = {})
|
28
|
+
migration_template(
|
29
|
+
"db/migrate/#{migration_name}",
|
30
|
+
"db/migrate/#{migration_name}",
|
31
|
+
config
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
# for generating a timestamp when using `create_migration`
|
36
|
+
def self.next_migration_number(dir)
|
37
|
+
ActiveRecord::Generators::Base.next_migration_number(dir)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateApps < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :apps do |t|
|
4
|
+
t.string :intercom_app_id, null: false
|
5
|
+
t.string :intercom_token, null: false
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
|
9
|
+
add_index :apps, :intercom_app_id, unique: true
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :apps
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module IntercomApp
|
4
|
+
module Generators
|
5
|
+
class ControllersGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../../../../..", __FILE__)
|
7
|
+
|
8
|
+
def create_controllers
|
9
|
+
controllers.each do |controller|
|
10
|
+
copy_file controller
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def controllers
|
17
|
+
files_within_root('.', 'app/controllers/intercom_app/*.*')
|
18
|
+
end
|
19
|
+
|
20
|
+
def files_within_root(prefix, glob)
|
21
|
+
root = "#{self.class.source_root}/#{prefix}"
|
22
|
+
|
23
|
+
Dir["#{root}/#{glob}"].sort.map do |full_path|
|
24
|
+
full_path.sub(root, '.').gsub('/./', '/')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module IntercomApp
|
4
|
+
module Generators
|
5
|
+
class HomeControllerGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_home_controller
|
9
|
+
template 'home_controller.rb', 'app/controllers/home_controller.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_home_index_view
|
13
|
+
copy_file 'index.html.erb', 'app/views/home/index.html.erb'
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_home_index_route
|
17
|
+
route "root :to => 'home#index'"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<% if IntercomApp.configuration.oauth_modal %>
|
2
|
+
<a href="javascript:void(0)" class="intercom-oauth-cta">
|
3
|
+
<img src="https://static.intercomassets.com/assets/oauth/primary-7edb2ebce84c088063f4b86049747c3a.png" srcset="https://static.intercomassets.com/assets/oauth/primary-7edb2ebce84c088063f4b86049747c3a.png 1x, https://static.intercomassets.com/assets/oauth/primary@2x-0d69ca2141dfdfa0535634610be80994.png 2x, https://static.intercomassets.com/assets/oauth/primary@3x-788ed3c44d63a6aec3927285e920f542.png 3x"/>
|
4
|
+
</a>
|
5
|
+
<script type="text/javascript">
|
6
|
+
$('.intercom-oauth-cta').unbind('click').click(function() {
|
7
|
+
var auth_window = window.open('/auth/intercom', 'Sign in', 'width=700,height=450');
|
8
|
+
var checkWindow = function() {
|
9
|
+
if (auth_window.closed) {
|
10
|
+
window.location = '/';
|
11
|
+
} else if (window.oauth_success === undefined) {
|
12
|
+
setTimeout(checkWindow, 200);
|
13
|
+
}
|
14
|
+
};
|
15
|
+
checkWindow();
|
16
|
+
});
|
17
|
+
</script>
|
18
|
+
<% else %>
|
19
|
+
<a href="/auth/intercom">Login</a>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<h1>Intercom application</h1>
|
23
|
+
<h2>List your <%= @users_count %> Intercom Users names :</h2>
|
24
|
+
<ul>
|
25
|
+
<% @users_names.each do | name | %>
|
26
|
+
<li> <%= name %></li>
|
27
|
+
<% end %>
|
28
|
+
</ul>
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module IntercomApp
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
class_option :app_key, type: :string, default: '<app_key>'
|
11
|
+
class_option :app_secret, type: :string, default: '<app_secret>'
|
12
|
+
class_option :oauth_modal, type: :boolean, default: false
|
13
|
+
|
14
|
+
def create_intercom_app_initializer
|
15
|
+
@app_key = options['app_key']
|
16
|
+
@app_secret = options['app_secret']
|
17
|
+
@oauth_modal = options['oauth_modal']
|
18
|
+
|
19
|
+
template 'intercom_app.rb', 'config/initializers/intercom_app.rb'
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_and_inject_into_omniauth_initializer
|
23
|
+
unless File.exist? "config/initializers/omniauth.rb"
|
24
|
+
copy_file 'omniauth.rb', 'config/initializers/omniauth.rb'
|
25
|
+
end
|
26
|
+
|
27
|
+
inject_into_file(
|
28
|
+
'config/initializers/omniauth.rb',
|
29
|
+
File.read(File.expand_path(find_in_source_paths('intercom_provider.rb'))),
|
30
|
+
after: "Rails.application.config.middleware.use OmniAuth::Builder do\n"
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_intercom_session_repository_initializer
|
35
|
+
copy_file 'intercom_session_repository.rb', 'config/initializers/intercom_session_repository.rb'
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def inject_into_application_controller
|
40
|
+
inject_into_class(
|
41
|
+
"app/controllers/application_controller.rb",
|
42
|
+
'ApplicationController',
|
43
|
+
" include IntercomApp::LoginProtection\n"
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def mount_engine
|
48
|
+
route "mount IntercomApp::Engine, at: '/'"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
IntercomApp::SessionRepository.storage = InMemorySessionStore
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module IntercomApp
|
2
|
+
module Generators
|
3
|
+
class IntercomAppGenerator < Rails::Generators::Base
|
4
|
+
def initialize(args, *options)
|
5
|
+
@opts = options.first
|
6
|
+
super(args, *options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def run_all_generators
|
10
|
+
generate "intercom_app:install #{@opts.join(' ')}"
|
11
|
+
generate "intercom_app:app_model"
|
12
|
+
generate "intercom_app:home_controller"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module IntercomApp
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
attr_accessor :app_key
|
5
|
+
attr_accessor :app_secret
|
6
|
+
attr_accessor :oauth_modal
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configuration=(config)
|
17
|
+
@configuration = config
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure
|
21
|
+
yield configuration
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# WARNING - This really only works for development, see README for more details
|
2
|
+
class InMemorySessionStore
|
3
|
+
class EnvironmentError < StandardError; end
|
4
|
+
|
5
|
+
def self.retrieve(id)
|
6
|
+
repo[id]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.store(session)
|
10
|
+
id = SecureRandom.uuid
|
11
|
+
repo[id] = session
|
12
|
+
id
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.clear
|
16
|
+
@@repo = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.repo
|
20
|
+
if Rails.env.production?
|
21
|
+
raise EnvironmentError.new("Cannot use InMemorySessionStore in a Production environment")
|
22
|
+
end
|
23
|
+
@@repo ||= {}
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module IntercomApp
|
2
|
+
module LoginProtection
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
# included do
|
6
|
+
# rescue_from ActiveResource::UnauthorizedAccess, :with => :close_session
|
7
|
+
# end
|
8
|
+
|
9
|
+
def intercom_session
|
10
|
+
if app_session
|
11
|
+
begin
|
12
|
+
@intercom_client = Intercom::Client.new(app_id: app_session[:token], api_key: '')
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
else
|
16
|
+
redirect_to_login
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def app_session
|
21
|
+
return unless session[:intercom]
|
22
|
+
@intercom_session ||= IntercomApp::SessionRepository.retrieve(session[:intercom])
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def redirect_to_login
|
28
|
+
if request.xhr?
|
29
|
+
head :unauthorized
|
30
|
+
else
|
31
|
+
session[:return_to] = request.fullpath if request.get?
|
32
|
+
redirect_to_with_fallback main_or_engine_login_url
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def close_session
|
37
|
+
session[:intercom] = nil
|
38
|
+
session[:intercom_app_id] = nil
|
39
|
+
redirect_to_with_fallback main_or_engine_login_url
|
40
|
+
end
|
41
|
+
|
42
|
+
def main_or_engine_login_url(params = {})
|
43
|
+
main_app.login_url(params)
|
44
|
+
rescue NoMethodError => e
|
45
|
+
intercom_app.login_url(params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def redirect_to_with_fallback(url)
|
49
|
+
url_json = url.to_json
|
50
|
+
url_json_no_quotes = url_json.gsub(/\A"|"\Z/, '')
|
51
|
+
|
52
|
+
render inline: %Q(
|
53
|
+
<!DOCTYPE html>
|
54
|
+
<html lang="en">
|
55
|
+
<head>
|
56
|
+
<meta charset="utf-8" />
|
57
|
+
<title>Redirecting…</title>
|
58
|
+
<script type="text/javascript">
|
59
|
+
window.location.href = #{url_json};
|
60
|
+
</script>
|
61
|
+
</head>
|
62
|
+
<body>
|
63
|
+
</body>
|
64
|
+
</html>
|
65
|
+
), status: 302, location: url
|
66
|
+
end
|
67
|
+
|
68
|
+
def fullpage_redirect_to(url)
|
69
|
+
url_json = url.to_json
|
70
|
+
url_json_no_quotes = url_json.gsub(/\A"|"\Z/, '')
|
71
|
+
redirect_to_with_fallback url
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module IntercomApp
|
2
|
+
class SessionRepository
|
3
|
+
class ConfigurationError < StandardError; end
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def storage=(storage)
|
7
|
+
@storage = storage
|
8
|
+
|
9
|
+
unless storage.nil? || self.storage.respond_to?(:store) && self.storage.respond_to?(:retrieve)
|
10
|
+
raise ArgumentError, "storage must respond to :store and :retrieve"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def retrieve(id)
|
15
|
+
storage.retrieve(id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def store(session)
|
19
|
+
storage.store(session)
|
20
|
+
end
|
21
|
+
|
22
|
+
def storage
|
23
|
+
load_storage || raise(ConfigurationError.new("SessionRepository.storage is not configured!"))
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def load_storage
|
29
|
+
return unless @storage
|
30
|
+
@storage.respond_to?(:safe_constantize) ? @storage.safe_constantize : @storage
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module IntercomApp
|
2
|
+
module SessionStorage
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def store(sess)
|
7
|
+
app = self.find_or_initialize_by(intercom_app_id: sess[:intercom_app_id])
|
8
|
+
app.intercom_token = sess[:token]
|
9
|
+
app.save!
|
10
|
+
app.id
|
11
|
+
end
|
12
|
+
|
13
|
+
def retrieve(id)
|
14
|
+
return unless id
|
15
|
+
if app = self.find_by(id: id)
|
16
|
+
session = {
|
17
|
+
id: app.id,
|
18
|
+
intercom_app_id: app.intercom_app_id,
|
19
|
+
token: app.intercom_token
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module IntercomApp
|
2
|
+
module SessionsConcern
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def login
|
6
|
+
redirect_to login_url
|
7
|
+
end
|
8
|
+
|
9
|
+
def callback
|
10
|
+
if response = request.env['omniauth.auth']
|
11
|
+
app = {
|
12
|
+
token: response['credentials']['token'],
|
13
|
+
intercom_app_id: response['extra']['raw_info']['app']['id_code']
|
14
|
+
}
|
15
|
+
session[:intercom] = IntercomApp::SessionRepository.store(app)
|
16
|
+
session[:intercom_app_id] = app[:intercom_app_id]
|
17
|
+
redirect_to return_address unless IntercomApp.configuration.oauth_modal
|
18
|
+
else
|
19
|
+
redirect_to login_url
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def destroy
|
24
|
+
session[:intercom] = nil
|
25
|
+
session[:intercom_app_id] = nil
|
26
|
+
redirect_to login_url
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def return_address
|
31
|
+
session.delete(:return_to) || '/'
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intercom-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Antoine
|
@@ -128,7 +128,48 @@ executables: []
|
|
128
128
|
extensions: []
|
129
129
|
extra_rdoc_files: []
|
130
130
|
files:
|
131
|
+
- ".github/ISSUE_TEMPLATE.md"
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CHANGELOG
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE
|
139
|
+
- README.md
|
140
|
+
- RELEASING
|
141
|
+
- Rakefile
|
142
|
+
- app/controllers/intercom_app/authenticated_controller.rb
|
143
|
+
- app/controllers/intercom_app/sessions_controller.rb
|
144
|
+
- app/models/intercom-app/app.rb
|
145
|
+
- app/views/intercom_app/sessions/callback.html.erb
|
146
|
+
- config/routes.rb
|
147
|
+
- intercom-app.gemspec
|
148
|
+
- lib/generators/intercom_app/app_model/app_model_generator.rb
|
149
|
+
- lib/generators/intercom_app/app_model/templates/app.rb
|
150
|
+
- lib/generators/intercom_app/app_model/templates/apps.yml
|
151
|
+
- lib/generators/intercom_app/app_model/templates/db/migrate/create_apps.rb
|
152
|
+
- lib/generators/intercom_app/app_model/templates/intercom_session_repository.rb
|
153
|
+
- lib/generators/intercom_app/controllers/controllers_generator.rb
|
154
|
+
- lib/generators/intercom_app/home_controller/home_controller_generator.rb
|
155
|
+
- lib/generators/intercom_app/home_controller/templates/home_controller.rb
|
156
|
+
- lib/generators/intercom_app/home_controller/templates/index.html.erb
|
157
|
+
- lib/generators/intercom_app/install/install_generator.rb
|
158
|
+
- lib/generators/intercom_app/install/templates/intercom_app.rb
|
159
|
+
- lib/generators/intercom_app/install/templates/intercom_provider.rb
|
160
|
+
- lib/generators/intercom_app/install/templates/intercom_session_repository.rb
|
161
|
+
- lib/generators/intercom_app/install/templates/omniauth.rb
|
162
|
+
- lib/generators/intercom_app/intercom_app_generator.rb
|
131
163
|
- lib/intercom-app.rb
|
164
|
+
- lib/intercom-app/app.rb
|
165
|
+
- lib/intercom-app/configuration.rb
|
166
|
+
- lib/intercom-app/engine.rb
|
167
|
+
- lib/intercom-app/in_memory_session_store.rb
|
168
|
+
- lib/intercom-app/login_protection.rb
|
169
|
+
- lib/intercom-app/session_repository.rb
|
170
|
+
- lib/intercom-app/session_storage.rb
|
171
|
+
- lib/intercom-app/sessions_concern.rb
|
172
|
+
- lib/intercom-app/version.rb
|
132
173
|
homepage: http://rubygems.org/gems/intercom-ruby-app
|
133
174
|
licenses:
|
134
175
|
- MIT
|
@@ -154,4 +195,3 @@ signing_key:
|
|
154
195
|
specification_version: 4
|
155
196
|
summary: Intercom.io ruby application boilerplate
|
156
197
|
test_files: []
|
157
|
-
has_rdoc:
|