kamiliff 0.29.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a255c2f6b73407c86e8f993716595072c3dc1c8c8a655df0b626c13719eae8d0
4
- data.tar.gz: 49b62ebd406218e682cb1fe2b68c7300695c53392cdce0938bc56fceb7c90e9a
3
+ metadata.gz: c1af1031691e8a44c53de0db7b33a2b0b6780c745e2132045ab423cad8ba8af9
4
+ data.tar.gz: a8735c527d1aa12471dd28c240e5cebb4e69cb3c15c95bd2e5c77ea5d845d26d
5
5
  SHA512:
6
- metadata.gz: e9a989ee028a5e130b7ba041e79a57279510e39672411263c5087bb162603d8ccc04bf46f9ef03c7f0e11007f1b6707f2e9b208d6d031d4b53a50aa58e1d327b
7
- data.tar.gz: '09fd775c392002cf34d7998ec020f779faa7a00fd977270056ac77ab786507cedc5187a6c2be1ebfe693389635a18fa5b815ef206af9791a72e5ff712533903f'
6
+ metadata.gz: 0a8b0cf61a6a580a936ea67dfc384d02dbf155ebdcc647a06ee82fd1f1077bf837ca3b4af7d4024701c919f136fcf7680e3fb6f39bcf8e17656b538df8701d25
7
+ data.tar.gz: a6f69448aa55004ba4561dfb6c95c54fccc27232a97a982f48c0909b932d017a672e50c9e9ef46fde9657cd2d4a23b2c0c82e26f0efe812e6ef3c09c16c05642
data/README.md CHANGED
@@ -123,3 +123,9 @@ Create by [etrex](https://etrex.tw)
123
123
 
124
124
  ## License
125
125
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
126
+
127
+ ## How to test this gem
128
+
129
+ ```
130
+ rails t
131
+ ```
@@ -23,7 +23,7 @@ class LiffController < ActionController::Base
23
23
  # fix liff 2.0 redirect issue
24
24
  @need_reload = query["liff.state"].present?
25
25
 
26
- # 需要從 session 讀取 @liff_param
26
+ # 需要從 session 讀取 @liff_param (使用電腦開啟 LIFF 頁面,第一次登入時的情況)
27
27
  if query["liffRedirectUri"].present?
28
28
  @liff_param = Base64DecodeService.new(session[:liff_param]).run
29
29
  session[:liff_param] = nil
@@ -75,22 +75,53 @@ class LiffController < ActionController::Base
75
75
  res&.to_s || e.full_message
76
76
  end
77
77
 
78
+
79
+ # profile format
80
+ # {
81
+ # "userId"=>"U1234567890abcdefghijklmnopqrstuv",
82
+ # "displayName"=>"user name",
83
+ # "statusMessage"=>"user status message",
84
+ # "pictureUrl"=>"https://this.is.an.image.url"
85
+ # }
78
86
  def source_info
79
87
  context = params["context"]
80
- return nil if context.nil?
81
-
82
- source_type = context["type"].gsub("utou", "user")
83
- source_group_id = context["roomId"] || context["groupId"] || context["userId"]
84
- source_user_id = context["userId"]
88
+ return {} if context.nil?
85
89
 
86
90
  profile = params["profile"]
91
+ return {} if profile.nil?
92
+
93
+ # authorize the user id
94
+ decoded_id_token = get_decoded_id_token
95
+ return {} unless decoded_id_token["sub"] == profile["userId"] && decoded_id_token["sub"] == profile["userId"]
96
+
97
+ source_type = context["type"].gsub("utou", "user")
98
+ source_group_id = context["roomId"] || context["groupId"] || decoded_id_token["sub"]
99
+ source_user_id = decoded_id_token["sub"]
87
100
 
88
101
  {
89
102
  platform_type: 'line',
90
103
  source_type: source_type,
91
104
  source_group_id: source_group_id,
92
105
  source_user_id: source_user_id,
93
- profile: profile
106
+ context: context,
107
+ profile: profile,
108
+ decoded_id_token: decoded_id_token
94
109
  }
95
110
  end
111
+
112
+ # decoded_id_token is JWT format
113
+ # {
114
+ # "iss"=>"https://access.line.me",
115
+ # "sub"=>"U1234567890abcdefghijklmnopqrstuv",
116
+ # "aud"=>"1234567890",
117
+ # "exp"=>1641638901,
118
+ # "iat"=>1641635301,
119
+ # "name"=>"user name",
120
+ # "picture"=>"https://this.is.an.image.url"
121
+ # }
122
+ def get_decoded_id_token
123
+ id_token = params["idToken"]
124
+ Kamiliff.line_login_client.verify_id_token(id_token: id_token)
125
+ end
126
+
96
127
  end
@@ -0,0 +1,16 @@
1
+ <%
2
+ messages = [messages] if messages.is_a? Hash
3
+ messages = messages.to_json if messages.is_a? Array
4
+ %>
5
+
6
+ <script>
7
+ (function(){
8
+ async function send_messages(){
9
+ const messages = <%= raw messages %>;
10
+ await liff.sendMessages(messages);
11
+ liff.closeWindow();
12
+ }
13
+
14
+ send_messages();
15
+ })();
16
+ </script>
@@ -1,3 +1,8 @@
1
+ <%
2
+ messages = [messages] if messages.is_a? Hash
3
+ messages = messages.to_json if messages.is_a? Array
4
+ %>
5
+
1
6
  <script>
2
7
  (function(){
3
8
  async function share_target_picker(messages){
@@ -38,12 +38,22 @@ let open_liff_page = (function(){
38
38
  }
39
39
  }
40
40
 
41
+ async function get_liff_profile(){
42
+ try{
43
+ return await liff.getProfile();
44
+ }catch(error){
45
+ return {};
46
+ }
47
+ }
48
+
41
49
  async function get_liff_data(){
42
- const profile = await liff.getProfile();
50
+ const profile = await get_liff_profile();
43
51
  const context = liff.getContext();
52
+ const idToken = liff.getIDToken();
44
53
  return {
45
- profile,
46
- context
54
+ context,
55
+ idToken,
56
+ profile
47
57
  }
48
58
  }
49
59
 
@@ -3,4 +3,4 @@
3
3
  # Add new mime types for use in respond_to blocks:
4
4
  # Mime::Type.register "text/richtext", :rtf
5
5
 
6
- Mime::Type.register "text/html", :liff
6
+ Mime::Type.register_alias "text/html", :liff
@@ -7,7 +7,8 @@ class Base64DecodeService
7
7
  end
8
8
 
9
9
  def run
10
- json = Base64.decode64(@base64_string)
10
+ string = @base64_string.tr('-','+').tr('_','/')
11
+ json = Base64.decode64(string)
11
12
  options = JSON.parse(json)
12
13
  options.with_indifferent_access
13
14
  end
@@ -1,3 +1,3 @@
1
1
  module Kamiliff
2
- VERSION = '0.29.0'
2
+ VERSION = '0.33.0'
3
3
  end
data/lib/kamiliff.rb CHANGED
@@ -2,7 +2,50 @@ require "kamiliff/engine"
2
2
  require "kamiliff/services/base64_encode_service"
3
3
  require "kamiliff/services/base64_decode_service"
4
4
  require "kamiliff/services/liff_service"
5
+ require "line_login"
5
6
 
6
7
  module Kamiliff
7
- # Your code goes here...
8
+ # env
9
+ mattr_writer :line_login_channel_id
10
+ mattr_writer :line_login_channel_secret
11
+ mattr_writer :line_login_redirect_uri
12
+
13
+ mattr_writer :liff_url_compact
14
+ mattr_writer :liff_url_tall
15
+ mattr_writer :liff_url_full
16
+
17
+ def self.line_login_channel_id
18
+ @@line_login_channel_id || ENV["LINE_LOGIN_CHANNEL_ID"]
19
+ end
20
+
21
+ def self.line_login_channel_secret
22
+ @@line_login_channel_secret || ENV["LINE_LOGIN_CHANNEL_SECRET"]
23
+ end
24
+
25
+ def self.line_login_redirect_uri
26
+ @@line_login_redirect_uri || ENV["LINE_LOGIN_REDIRECT_URI"]
27
+ end
28
+
29
+ def self.liff_url_compact
30
+ @@liff_url_compact || ENV["LIFF_COMPACT"]
31
+ end
32
+
33
+ def self.liff_url_tall
34
+ @@liff_url_tall || ENV["LIFF_TALL"]
35
+ end
36
+
37
+ def self.liff_url_full
38
+ @@liff_url_full || ENV["LIFF_FULL"]
39
+ end
40
+
41
+ def self.line_login_client
42
+ @line_login_client ||= LineLogin::Client.new(
43
+ client_id: Kamiliff.line_login_channel_id,
44
+ client_secret: Kamiliff.line_login_channel_secret
45
+ )
46
+ end
47
+
48
+ def self.setup
49
+ yield self
50
+ end
8
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamiliff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - etrex kuo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-29 00:00:00.000000000 Z
11
+ date: 2022-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: line_login
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.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.1.0
27
41
  description: An easy way to use LINE Front-end Framework(LIFF) on rails.
28
42
  email:
29
43
  - et284vu065k3@gmail.com
@@ -39,6 +53,7 @@ files:
39
53
  - app/helpers/liff_helper.rb
40
54
  - app/views/layouts/application.liff.erb
41
55
  - app/views/layouts/liff.html.erb
56
+ - app/views/liff/_send_messages.liff.erb
42
57
  - app/views/liff/_share_target_picker.liff.erb
43
58
  - app/views/liff/entry.html.erb
44
59
  - app/views/liff/route.html.erb
@@ -72,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
87
  - !ruby/object:Gem::Version
73
88
  version: '0'
74
89
  requirements: []
75
- rubygems_version: 3.1.2
90
+ rubygems_version: 3.1.4
76
91
  signing_key:
77
92
  specification_version: 4
78
93
  summary: An easy way to use LINE Front-end Framework(LIFF) on rails.