kamiliff 0.31.0 → 0.35.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 955111b68428e0cc0e93dbae9efb62e05c5fadcdff1ea4c54f18fa0cc8fd3bda
4
- data.tar.gz: 72bcfbce267e8ffc9697eb4477dea346f7e3af54aaec07c83191823f37e12ae4
3
+ metadata.gz: 5cadd63601665e9929d92e4a388c7302da061204ac677151e3f31bd22f3ad5df
4
+ data.tar.gz: 062cdd8edc89cbf4b01b6d7cfd7308f19d31ea1364b5d7b2032dfe749a0104dc
5
5
  SHA512:
6
- metadata.gz: 480280f31fc7637bb3a013d67c8255dc4e54b5bb6fe9fd6b92ba61cb6d6148d047e27c53ded5ab4a299cfb2cdb308196198716268fcb1809066fecd3081dfb77
7
- data.tar.gz: 98e29a589edd018a0382072bd55d45e70189d6f3a7d4727828069deba66af7cd5e92329963841701feed672751c3c79144a9743cfda6bc00f2d3523785eb7e3b
6
+ metadata.gz: 04c61b4c8aea5c4b54cb788353d8c8ed46ff7d44e978088a723449327d4baf0ed53254c56d618fb0f233b84ee2df9c7b8570c6f2460815afdccf8ff21e0d4558
7
+ data.tar.gz: 64123903cf8a36641ffae41b9ca42f77d41034f1174f5822792ea77029ff13c31d76f43a08b4e4c587dd1928882c972233205cef6dd717859c42fc49886b7219
@@ -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,74 @@ 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
+ context: context,
98
+ } if profile.nil?
99
+
100
+ # authorize the user id
101
+ decoded_id_token = get_decoded_id_token
102
+
103
+ return {
104
+ platform_type: 'line',
105
+ liff_error: 'id token not found',
106
+ context: context,
107
+ profile: profile,
108
+ } if params["idToken"].nil?
109
+
110
+ return {
111
+ platform_type: 'line',
112
+ liff_error: 'user id does not match',
113
+ context: context,
114
+ profile: profile,
115
+ decoded_id_token: decoded_id_token
116
+ } unless decoded_id_token["sub"] == context["userId"] && decoded_id_token["sub"] == profile["userId"]
117
+
118
+ source_type = context["type"].gsub("utou", "user")
119
+ source_group_id = context["roomId"] || context["groupId"] || decoded_id_token["sub"]
120
+ source_user_id = decoded_id_token["sub"]
87
121
 
88
122
  {
89
123
  platform_type: 'line',
90
124
  source_type: source_type,
91
125
  source_group_id: source_group_id,
92
126
  source_user_id: source_user_id,
93
- profile: profile
127
+ context: context,
128
+ profile: profile,
129
+ decoded_id_token: decoded_id_token
94
130
  }
95
131
  end
132
+
133
+ # decoded_id_token is JWT format
134
+ # {
135
+ # "iss"=>"https://access.line.me",
136
+ # "sub"=>"U1234567890abcdefghijklmnopqrstuv",
137
+ # "aud"=>"1234567890",
138
+ # "exp"=>1641638901,
139
+ # "iat"=>1641635301,
140
+ # "name"=>"user name",
141
+ # "picture"=>"https://this.is.an.image.url"
142
+ # }
143
+ def get_decoded_id_token
144
+ id_token = params["idToken"]
145
+ Kamiliff.line_login_client.verify_id_token(id_token: id_token)
146
+ end
147
+
96
148
  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
 
@@ -1,3 +1,3 @@
1
1
  module Kamiliff
2
- VERSION = '0.31.0'
2
+ VERSION = '0.35.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.31.0
4
+ version: 0.35.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-08-07 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.