From 400ce0c6ff88aeebce08fa5297acdf3f5898cfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=9Awi=C4=85tkowski?= Date: Tue, 22 Sep 2020 22:52:29 +0200 Subject: [PATCH 1/4] Test using latest Crystal version on CI --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index ffc7b6a..4aea673 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,4 @@ +dist: xenial language: crystal +crystal: +- latest \ No newline at end of file From dc16e179f5da49ed2ea34895caf22ee186f2a498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=9Awi=C4=85tkowski?= Date: Tue, 22 Sep 2020 22:56:07 +0200 Subject: [PATCH 2/4] Use request_body autho scheme for OAuth In Crystal 0.35 the default scheme for OAuth::Client changed from request_body to basic_auth. The code here works on a request_body mode so it has to be update accordingly. See: https://github.com/crystal-lang/crystal/commit/b8d4ca0de1ca39c88fc959fb2a5e1bcd2b1cc153 --- src/multi_auth/providers/facebook.cr | 3 ++- src/multi_auth/providers/github.cr | 3 ++- src/multi_auth/providers/google.cr | 3 ++- src/multi_auth/providers/vk.cr | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/multi_auth/providers/facebook.cr b/src/multi_auth/providers/facebook.cr index a7c5d03..a9e67a9 100644 --- a/src/multi_auth/providers/facebook.cr +++ b/src/multi_auth/providers/facebook.cr @@ -75,7 +75,8 @@ class MultiAuth::Provider::Facebook < MultiAuth::Provider key, secret, redirect_uri: redirect_uri, - token_uri: "/v2.9/oauth/access_token" + token_uri: "/v2.9/oauth/access_token", + auth_scheme: :request_body ) end end diff --git a/src/multi_auth/providers/github.cr b/src/multi_auth/providers/github.cr index 8cc8a8b..ddbd649 100644 --- a/src/multi_auth/providers/github.cr +++ b/src/multi_auth/providers/github.cr @@ -65,7 +65,8 @@ class MultiAuth::Provider::Github < MultiAuth::Provider key, secret, authorize_uri: "/login/oauth/authorize", - token_uri: "/login/oauth/access_token" + token_uri: "/login/oauth/access_token", + auth_scheme: :request_body ) end end diff --git a/src/multi_auth/providers/google.cr b/src/multi_auth/providers/google.cr index 62a3be8..53a556f 100644 --- a/src/multi_auth/providers/google.cr +++ b/src/multi_auth/providers/google.cr @@ -27,7 +27,8 @@ class MultiAuth::Provider::Google < MultiAuth::Provider key, secret, token_uri: "/oauth2/v4/token", - redirect_uri: redirect_uri + redirect_uri: redirect_uri, + auth_scheme: :request_body ) access_token = client.get_access_token_using_authorization_code(params["code"]) diff --git a/src/multi_auth/providers/vk.cr b/src/multi_auth/providers/vk.cr index 5c06e3d..fc9282f 100644 --- a/src/multi_auth/providers/vk.cr +++ b/src/multi_auth/providers/vk.cr @@ -99,7 +99,8 @@ class MultiAuth::Provider::Vk < MultiAuth::Provider secret, redirect_uri: redirect_uri, authorize_uri: "/authorize", - token_uri: "/access_token" + token_uri: "/access_token", + auth_scheme: :request_body ) end end From dff240a1a2409569aaf349d57a43773ddfb03f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=9Awi=C4=85tkowski?= Date: Tue, 22 Sep 2020 23:12:42 +0200 Subject: [PATCH 3/4] Use JSON::Serializable instead of deprecated JSON.mapping --- src/multi_auth/providers/facebook.cr | 20 +++++++-------- src/multi_auth/providers/github.cr | 24 ++++++++++-------- src/multi_auth/providers/twitter.cr | 22 ++++++++-------- src/multi_auth/providers/vk.cr | 38 ++++++++++++++-------------- 4 files changed, 54 insertions(+), 50 deletions(-) diff --git a/src/multi_auth/providers/facebook.cr b/src/multi_auth/providers/facebook.cr index a9e67a9..dd5206a 100644 --- a/src/multi_auth/providers/facebook.cr +++ b/src/multi_auth/providers/facebook.cr @@ -29,20 +29,20 @@ class MultiAuth::Provider::Facebook < MultiAuth::Provider end private class FbUser + include JSON::Serializable + property raw_json : String? property access_token : OAuth2::AccessToken? property picture_url : String? - JSON.mapping( - id: String, - name: String, - last_name: String?, - first_name: String?, - email: String?, - location: String?, - about: String?, - website: String? - ) + property id : String + property name : String + property last_name : String? + property first_name : String? + property email : String? + property location : String? + property about : String? + property website : String? end private def fetch_fb_user(code) diff --git a/src/multi_auth/providers/github.cr b/src/multi_auth/providers/github.cr index ddbd649..9d6b025 100644 --- a/src/multi_auth/providers/github.cr +++ b/src/multi_auth/providers/github.cr @@ -30,20 +30,22 @@ class MultiAuth::Provider::Github < MultiAuth::Provider end private class GhUser + include JSON::Serializable + property raw_json : String? property access_token : OAuth2::AccessToken? - JSON.mapping( - id: {type: String, converter: String::RawConverter}, - name: String, - email: String?, - login: String, - location: String?, - bio: String?, - avatar_url: String?, - blog: String?, - html_url: String? - ) + @[JSON::Field(converter: String::RawConverter)] + property id : String + + property name : String + property email : String? + property login : String + property location : String? + property bio : String? + property avatar_url : String? + property blog : String? + property html_url : String? end private def fetch_gh_user(code) diff --git a/src/multi_auth/providers/twitter.cr b/src/multi_auth/providers/twitter.cr index 62bd467..6c6c83e 100644 --- a/src/multi_auth/providers/twitter.cr +++ b/src/multi_auth/providers/twitter.cr @@ -28,19 +28,21 @@ class MultiAuth::Provider::Twitter < MultiAuth::Provider end private class TwUser + include JSON::Serializable + property raw_json : String? property access_token : OAuth::AccessToken? - JSON.mapping( - id: {type: String, converter: String::RawConverter}, - name: String, - screen_name: String, - location: String?, - description: String?, - url: String?, - profile_image_url: String?, - email: String? - ) + @[JSON::Field(converter: String::RawConverter)] + property id : String + + property name : String + property screen_name : String + property location : String? + property description : String? + property url : String? + property profile_image_url : String? + property email : String? end private def fetch_tw_user(oauth_token, oauth_verifier) diff --git a/src/multi_auth/providers/vk.cr b/src/multi_auth/providers/vk.cr index fc9282f..07cd45c 100644 --- a/src/multi_auth/providers/vk.cr +++ b/src/multi_auth/providers/vk.cr @@ -36,12 +36,13 @@ class MultiAuth::Provider::Vk < MultiAuth::Provider end class VkTitle - JSON.mapping( - title: String - ) + include JSON::Serializable + property title : String end class VkUser + include JSON::Serializable + property raw_json : String? property access_token : OAuth2::AccessToken? property email : String? @@ -51,25 +52,24 @@ class MultiAuth::Provider::Vk < MultiAuth::Provider "#{last_name} #{first_name}" end - JSON.mapping( - id: {type: String, converter: String::RawConverter}, - last_name: String?, - first_name: String?, - site: String?, - city: VkTitle?, - country: VkTitle?, - domain: String?, - about: String?, - photo_max_orig: String?, - mobile_phone: String?, - home_phone: String? - ) + @[JSON::Field(converter: String::RawConverter)] + property id : String + + property last_name : String? + property first_name : String? + property site : String? + property city : VkTitle? + property country : VkTitle? + property domain : String? + property about : String? + property photo_max_orig : String? + property mobile_phone : String? + property home_phone : String? end class VkResponse - JSON.mapping( - response: Array(VkUser), - ) + include JSON::Serializable + property response : Array(VkUser) end private def fetch_vk_user(code) From f48162074dcf683b0a86a50ef884f79b39012ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=9Awi=C4=85tkowski?= Date: Tue, 22 Sep 2020 23:19:26 +0200 Subject: [PATCH 4/4] Use 0.35.1 in docker and shards.yml --- docker-compose.yml | 2 +- shard.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 013b63e..fb8a992 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: app: - image: crystallang/crystal:0.29.0 + image: crystallang/crystal:0.35.1 working_dir: /app environment: EDA_ENV: ${MULTI_AUTH_ENV} diff --git a/shard.yml b/shard.yml index 834e1f1..7cd7724 100644 --- a/shard.yml +++ b/shard.yml @@ -4,7 +4,7 @@ version: 1.0.0 authors: - Sergey Makridenkov -crystal: 0.29.0 +crystal: 0.35.1 license: MIT