kamiliff 0.30.0 → 0.34.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: ab829402ca3be1e4abb919a2aa749300880defcd4a83f34722295fde8c630a4d
4
- data.tar.gz: 258646936128084b87188a5f8cff334a3a3eb10014802fa2ce2169d79cfd21ab
3
+ metadata.gz: 11cfdd6d0774b7633ec67141f49a41b8c34a6ae057f076bf91aaae555538236b
4
+ data.tar.gz: c2a05f104e9c15bfa8a287a25b7d8686d5e72d9798282af560b0f7bc274f3642
5
5
  SHA512:
6
- metadata.gz: 133c3d84174a56c589d79c26c29786b1e68d5fd38e6dd72f50061b3a6d8c0f7c51bfe5fec6365744f5c9a6564c23825597f3454e0ac546f15442c9b30689c11d
7
- data.tar.gz: '0484a56b8f8d10c570d6377f745cdc441a8a2dca505468530da92f48bee0a23eadd13fdf4e9647c71f4e1ec5d9b5a75bf17add44d0d3274895bc0e099a33603b'
6
+ metadata.gz: 2a69c31a08788456a74fd2211ca1d607b87f69f5b1c6b0e56d43466f84225b768069637680d5c567091918c8999d1d0e1cd1a594015edd9423a3b54928917b46
7
+ data.tar.gz: c3cd30b0d24bb39ec6ff7c6fe4c8fa19f436a56e967db1461904e21c7fa4ada0ebb2e9f4a7ea633f4bbe09f3a31f26f396f1816b8153a34f8eb14e90d5574c94
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,62 @@ 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 {
89
+ platform_type: 'line',
90
+ liff_error: 'context not found',
91
+ } if context.nil?
85
92
 
86
93
  profile = params["profile"]
94
+ return {
95
+ platform_type: 'line',
96
+ liff_error: 'profile not found',
97
+ } if profile.nil?
98
+
99
+ # authorize the user id
100
+ decoded_id_token = get_decoded_id_token
101
+ return {
102
+ platform_type: 'line',
103
+ liff_error: 'user id does not match',
104
+ } unless decoded_id_token["sub"] == context["userId"] && decoded_id_token["sub"] == profile["userId"]
105
+
106
+ source_type = context["type"].gsub("utou", "user")
107
+ source_group_id = context["roomId"] || context["groupId"] || decoded_id_token["sub"]
108
+ source_user_id = decoded_id_token["sub"]
87
109
 
88
110
  {
89
111
  platform_type: 'line',
90
112
  source_type: source_type,
91
113
  source_group_id: source_group_id,
92
114
  source_user_id: source_user_id,
93
- profile: profile
115
+ context: context,
116
+ profile: profile,
117
+ decoded_id_token: decoded_id_token
94
118
  }
95
119
  end
120
+
121
+ # decoded_id_token is JWT format
122
+ # {
123
+ # "iss"=>"https://access.line.me",
124
+ # "sub"=>"U1234567890abcdefghijklmnopqrstuv",
125
+ # "aud"=>"1234567890",
126
+ # "exp"=>1641638901,
127
+ # "iat"=>1641635301,
128
+ # "name"=>"user name",
129
+ # "picture"=>"https://this.is.an.image.url"
130
+ # }
131
+ def get_decoded_id_token
132
+ id_token = params["idToken"]
133
+ Kamiliff.line_login_client.verify_id_token(id_token: id_token)
134
+ end
135
+
96
136
  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
@@ -1,3 +1,3 @@
1
1
  module Kamiliff
2
- VERSION = '0.30.0'
2
+ VERSION = '0.34.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.30.0
4
+ version: 0.34.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-07-24 00:00:00.000000000 Z
11
+ date: 2022-01-22 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.