Skip to content

Commit d4cc171

Browse files
committed
Revert "fix(google): can't mix admin with calendar scopes"
This reverts commit 9fca2ba.
1 parent d42d974 commit d4cc171

File tree

4 files changed

+16
-33
lines changed

4 files changed

+16
-33
lines changed

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: place_calendar
2-
version: 3.0.0
2+
version: 2.0.1
33

44
authors:
55
- Toby Carvan <toby@redant.com.au>

spec/spec_helper.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ end
1212
def google_creds
1313
{
1414
file_path: "",
15-
# scopes: "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/directory.user.readonly https://www.googleapis.com/auth/drive",
16-
domain: "",
17-
sub: "",
15+
scopes: "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/directory.user.readonly https://www.googleapis.com/auth/drive",
16+
domain: "",
17+
sub: "",
1818
}
1919
end
2020

src/google.cr

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ module PlaceCalendar
44
class Google < Interface
55
def initialize(
66
@file_path : String,
7+
@scopes : String | Array(String),
78
@domain : String,
8-
@calendar_scope : String = "https://www.googleapis.com/auth/calendar",
9-
@directory_scope : String = "https://www.googleapis.com/auth/admin.directory.user.readonly",
109
@sub : String = "",
1110
@user_agent : String = "PlaceOS"
1211
)
@@ -17,20 +16,19 @@ module PlaceCalendar
1716
def initialize(
1817
@issuer : String,
1918
@signing_key : String,
19+
@scopes : String | Array(String),
2020
@domain : String,
21-
@calendar_scope : String = "https://www.googleapis.com/auth/calendar",
22-
@directory_scope : String = "https://www.googleapis.com/auth/admin.directory.user.readonly",
2321
@sub : String = "",
2422
@user_agent : String = "PlaceOS"
2523
)
2624
@file_path = ""
2725
end
2826

29-
def auth(scope, sub = @sub) : ::Google::FileAuth | ::Google::Auth
27+
def auth(sub = @sub) : ::Google::FileAuth | ::Google::Auth
3028
if @file_path.empty?
31-
::Google::Auth.new(issuer: @issuer, signing_key: @signing_key, scopes: scope, sub: sub, user_agent: @user_agent)
29+
::Google::Auth.new(issuer: @issuer, signing_key: @signing_key, scopes: @scopes, sub: sub, user_agent: @user_agent)
3230
else
33-
::Google::FileAuth.new(file_path: @file_path, scopes: scope, sub: sub, user_agent: @user_agent)
31+
::Google::FileAuth.new(file_path: @file_path, scopes: @scopes, sub: sub, user_agent: @user_agent)
3432
end
3533
rescue ex : ::Google::Exception
3634
handle_google_exception(ex)
@@ -128,19 +126,19 @@ module PlaceCalendar
128126
end
129127

130128
def directory : ::Google::Directory
131-
@directory ||= ::Google::Directory.new(auth: auth(@directory_scope), domain: @domain)
129+
@directory ||= ::Google::Directory.new(auth: auth, domain: @domain)
132130
end
133131

134132
def calendar(sub = @sub)
135-
@calendar ||= ::Google::Calendar.new(auth: auth(@calendar_scope, sub))
133+
@calendar ||= ::Google::Calendar.new(auth: auth(sub))
136134
end
137135

138136
private def handle_google_exception(ex : ::Google::Exception)
139137
raise PlaceCalendar::Exception.new(ex.http_status, ex.http_body, ex.message)
140138
end
141139

142140
private def drive_files(sub = @sub)
143-
@drive_files ||= ::Google::Files.new(auth: auth("https://www.googleapis.com/auth/drive.file", sub))
141+
@drive_files ||= ::Google::Files.new(auth: auth(sub))
144142
end
145143

146144
private def event_params(event, calendar_id)

src/place_calendar.cr

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,12 @@ module PlaceCalendar
2525
list_attachments, get_attachment, create_attachment, delete_attachment,
2626
get_availability, to: @calendar
2727

28-
def initialize(
29-
file_path : String,
30-
domain : String,
31-
calendar_scope : String = "https://www.googleapis.com/auth/calendar",
32-
directory_scope : String = "https://www.googleapis.com/auth/admin.directory.user.readonly",
33-
sub : String = "",
34-
user_agent = "PlaceOS"
35-
)
36-
@calendar = Google.new(file_path, domain, calendar_scope, directory_scope, sub, user_agent)
28+
def initialize(file_path : String, scopes : String | Array(String), domain : String, sub : String = "", user_agent = "PlaceOS")
29+
@calendar = Google.new(file_path, scopes, domain, sub, user_agent)
3730
end
3831

39-
def initialize(
40-
issuer : String,
41-
signing_key : String,
42-
domain : String,
43-
calendar_scope : String = "https://www.googleapis.com/auth/calendar",
44-
directory_scope : String = "https://www.googleapis.com/auth/admin.directory.user.readonly",
45-
sub : String = "",
46-
user_agent = "PlaceOS"
47-
)
48-
@calendar = Google.new(issuer, signing_key, domain, calendar_scope, directory_scope, sub, user_agent)
32+
def initialize(issuer : String, signing_key : String, scopes : String | Array(String), domain : String, sub : String = "", user_agent = "PlaceOS")
33+
@calendar = Google.new(issuer, signing_key, scopes, domain, sub, user_agent)
4934
end
5035

5136
def initialize(tenant : String, client_id : String, client_secret : String)

0 commit comments

Comments
 (0)