diff --git a/README.md b/README.md index 8c43de8..3835562 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,7 @@ information contained in the token via the following instance methods: * `locale` +* `hosted_domain`: The hosted G Suite domain of the user, provided only if user belongs to a hosted domain. ## Security diff --git a/lib/google_sign_in/identity.rb b/lib/google_sign_in/identity.rb index e62f4b1..2245bda 100644 --- a/lib/google_sign_in/identity.rb +++ b/lib/google_sign_in/identity.rb @@ -36,6 +36,10 @@ def locale @payload["locale"] end + def hosted_domain + @payload["hd"] + end + private delegate :client_id, to: GoogleSignIn diff --git a/test/models/identity_test.rb b/test/models/identity_test.rb index fcece54..781f290 100644 --- a/test/models/identity_test.rb +++ b/test/models/identity_test.rb @@ -61,6 +61,10 @@ class GoogleSignIn::IdentityTest < ActiveSupport::TestCase assert_equal "en-US", GoogleSignIn::Identity.new(token_with(locale: "en-US")).locale end + test "extracting hosted_domain on google apps identity" do + assert_equal "basecamp.com", GoogleSignIn::Identity.new(token_with(hd: "basecamp.com")).hosted_domain + end + private def switch_client_id_to(value) previous_value = GoogleSignIn.client_id