discourse_api 0.19.0 → 0.20.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -1
- data/lib/discourse_api/error.rb +8 -5
- data/lib/discourse_api/single_sign_on.rb +18 -17
- data/lib/discourse_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f274e6981e46cd2e393462cb9df4f24c8933aa5a
|
4
|
+
data.tar.gz: de4fded436009054fd23e9b889a3437ae6350452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 255799bc16658b2c84945ba46e349126a095590dd869d2b715a58dc2a03e3a3cf4e008764b2e8fab29c3d544301391a77068f5a84ff433fa69ffceffec2a51ab
|
7
|
+
data.tar.gz: 61d1bb2ce5287e6666be41546948477a9baad9a122d14d004ed12156bd6d22aa967bace0160b9d31b0ccdda5463dbd0ac548c81f9761704b8336e8f24d099395
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [0.20.0] - 2017-12-13
|
6
|
+
### Added
|
7
|
+
- Add base error class
|
8
|
+
### Fixed
|
9
|
+
- Update SSO
|
10
|
+
|
5
11
|
## [0.19.0] - 2017-11-22
|
6
12
|
### Added
|
7
13
|
- Added optional `create_post` params
|
data/README.md
CHANGED
@@ -80,4 +80,5 @@ client.create_private_message( #=> Creates a private messages b
|
|
80
80
|
1. Install discourse locally
|
81
81
|
2. Inside of your discourse directory, run: `bundle exec rake db:api_test_seed`
|
82
82
|
3. Start discourse: `bundle exec rails s`
|
83
|
-
4.
|
83
|
+
4. Install bundler in the discourse_api directory, run `gem install bundler`
|
84
|
+
5. Inside of your discourse_api directory, run: `bundle exec rspec spec/`
|
data/lib/discourse_api/error.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module DiscourseApi
|
2
|
-
class
|
2
|
+
class DiscourseError < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class Error < DiscourseError
|
3
6
|
attr_reader :wrapped_exception
|
4
7
|
|
5
8
|
# Initializes a new Error object
|
@@ -12,15 +15,15 @@ module DiscourseApi
|
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
15
|
-
class UnauthenticatedError <
|
18
|
+
class UnauthenticatedError < DiscourseError
|
16
19
|
end
|
17
20
|
|
18
|
-
class NotFoundError <
|
21
|
+
class NotFoundError < DiscourseError
|
19
22
|
end
|
20
23
|
|
21
|
-
class UnprocessableEntity <
|
24
|
+
class UnprocessableEntity < DiscourseError
|
22
25
|
end
|
23
26
|
|
24
|
-
class TooManyRequests <
|
27
|
+
class TooManyRequests < DiscourseError
|
25
28
|
end
|
26
29
|
end
|
@@ -4,14 +4,16 @@ require 'openssl'
|
|
4
4
|
|
5
5
|
module DiscourseApi
|
6
6
|
class SingleSignOn
|
7
|
-
ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :avatar_force_update,
|
8
|
-
:
|
7
|
+
ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :avatar_force_update, :require_activation,
|
8
|
+
:bio, :external_id, :return_sso_url, :admin, :moderator, :suppress_welcome_message, :title,
|
9
|
+
:add_groups, :remove_groups, :groups]
|
9
10
|
FIXNUMS = []
|
10
|
-
BOOLS = [:avatar_force_update, :admin, :moderator, :suppress_welcome_message]
|
11
|
+
BOOLS = [:avatar_force_update, :admin, :moderator, :require_activation, :suppress_welcome_message]
|
12
|
+
ARRAYS = [:groups]
|
11
13
|
#NONCE_EXPIRY_TIME = 10.minutes # minutes is a rails method and is causing an error. Is this needed in the api?
|
12
14
|
|
13
15
|
attr_accessor(*ACCESSORS)
|
14
|
-
|
16
|
+
attr_writer :sso_secret, :sso_url
|
15
17
|
|
16
18
|
def self.sso_secret
|
17
19
|
raise RuntimeError, "sso_secret not implemented on class, be sure to set it on instance"
|
@@ -44,15 +46,12 @@ module DiscourseApi
|
|
44
46
|
if BOOLS.include? k
|
45
47
|
val = ["true", "false"].include?(val) ? val == "true" : nil
|
46
48
|
end
|
49
|
+
val = Array(val) if ARRAYS.include?(k) && !val.nil?
|
47
50
|
sso.send("#{k}=", val)
|
48
51
|
end
|
49
52
|
|
50
|
-
decoded_hash.each do |k,v|
|
51
|
-
|
52
|
-
# custom.
|
53
|
-
#
|
54
|
-
if k[0..6] == "custom."
|
55
|
-
field = k[7..-1]
|
53
|
+
decoded_hash.each do |k, v|
|
54
|
+
if field = k[/^custom\.(.+)$/, 1]
|
56
55
|
sso.custom_fields[field] = v
|
57
56
|
end
|
58
57
|
end
|
@@ -60,6 +59,10 @@ module DiscourseApi
|
|
60
59
|
sso
|
61
60
|
end
|
62
61
|
|
62
|
+
def diagnostics
|
63
|
+
DiscourseApi::SingleSignOn::ACCESSORS.map { |a| "#{a}: #{send(a)}" }.join("\n")
|
64
|
+
end
|
65
|
+
|
63
66
|
def sso_secret
|
64
67
|
@sso_secret || self.class.sso_secret
|
65
68
|
end
|
@@ -72,32 +75,30 @@ module DiscourseApi
|
|
72
75
|
@custom_fields ||= {}
|
73
76
|
end
|
74
77
|
|
75
|
-
|
76
78
|
def sign(payload)
|
77
79
|
OpenSSL::HMAC.hexdigest("sha256", sso_secret, payload)
|
78
80
|
end
|
79
81
|
|
80
|
-
|
81
|
-
def to_url(base_url=nil)
|
82
|
+
def to_url(base_url = nil)
|
82
83
|
base = "#{base_url || sso_url}"
|
83
84
|
"#{base}#{base.include?('?') ? '&' : '?'}#{payload}"
|
84
85
|
end
|
85
86
|
|
86
87
|
def payload
|
87
|
-
payload = Base64.
|
88
|
+
payload = Base64.strict_encode64(unsigned_payload)
|
88
89
|
"sso=#{CGI::escape(payload)}&sig=#{sign(payload)}"
|
89
90
|
end
|
90
91
|
|
91
92
|
def unsigned_payload
|
92
93
|
payload = {}
|
93
|
-
ACCESSORS.each do |k|
|
94
|
-
next if (val = send k) == nil
|
95
94
|
|
95
|
+
ACCESSORS.each do |k|
|
96
|
+
next if (val = send k) == nil
|
96
97
|
payload[k] = val
|
97
98
|
end
|
98
99
|
|
99
100
|
if @custom_fields
|
100
|
-
@custom_fields.each do |k,v|
|
101
|
+
@custom_fields.each do |k, v|
|
101
102
|
payload["custom.#{k}"] = v.to_s
|
102
103
|
end
|
103
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-
|
14
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|
@@ -307,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
307
307
|
version: '0'
|
308
308
|
requirements: []
|
309
309
|
rubyforge_project:
|
310
|
-
rubygems_version: 2.
|
310
|
+
rubygems_version: 2.6.8
|
311
311
|
signing_key:
|
312
312
|
specification_version: 4
|
313
313
|
summary: Allows access to the Discourse API
|