kamiliff 0.32.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: 36670cc34affa11b01f78976bd3630a7a5cae7061f420a83e4c5a4ae4e49c118
4
- data.tar.gz: 439962ffdba9c96506dd942d876c28888d6c49054db21faa7e19454f598c3d9c
3
+ metadata.gz: c1af1031691e8a44c53de0db7b33a2b0b6780c745e2132045ab423cad8ba8af9
4
+ data.tar.gz: a8735c527d1aa12471dd28c240e5cebb4e69cb3c15c95bd2e5c77ea5d845d26d
5
5
  SHA512:
6
- metadata.gz: ad8417dbe7cdd11be8b7a147887812485ea313994795673479432997f0bd94d2f896c05bde1b30eedd74b7d1157ae92d8d9d7f97327cd45944e4b6472ff49e01
7
- data.tar.gz: e89b3b1e26bb1f9ba1d76c388dff2029cd0e344f2187330c8930607401b697c0c093c6e008a84afb60cf96203f94788e01d4b847e2f8828b47dcae77f5cdf5bb
6
+ metadata.gz: 0a8b0cf61a6a580a936ea67dfc384d02dbf155ebdcc647a06ee82fd1f1077bf837ca3b4af7d4024701c919f136fcf7680e3fb6f39bcf8e17656b538df8701d25
7
+ data.tar.gz: a6f69448aa55004ba4561dfb6c95c54fccc27232a97a982f48c0909b932d017a672e50c9e9ef46fde9657cd2d4a23b2c0c82e26f0efe812e6ef3c09c16c05642
@@ -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
@@ -49,9 +49,11 @@ let open_liff_page = (function(){
49
49
  async function get_liff_data(){
50
50
  const profile = await get_liff_profile();
51
51
  const context = liff.getContext();
52
+ const idToken = liff.getIDToken();
52
53
  return {
53
- profile,
54
- context
54
+ context,
55
+ idToken,
56
+ profile
55
57
  }
56
58
  }
57
59
 
@@ -1,3 +1,3 @@
1
1
  module Kamiliff
2
- VERSION = '0.32.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.32.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-10-11 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