Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter to extract hd for G Suite domains #15

Merged
merged 2 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ information contained in the token via the following instance methods:

* `locale`

* `hd`: The hosted G Suite domain of the user, provided only if user belongs to a hosted domain.
MattWalston marked this conversation as resolved.
Show resolved Hide resolved

## Security

Expand Down
4 changes: 4 additions & 0 deletions lib/google_sign_in/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def locale
@payload["locale"]
end

def hd
@payload["hd"]
end
MattWalston marked this conversation as resolved.
Show resolved Hide resolved

private
delegate :client_id, to: GoogleSignIn

Expand Down
7 changes: 7 additions & 0 deletions test/models/identity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class GoogleSignIn::IdentityTest < ActiveSupport::TestCase
assert_equal "en-US", GoogleSignIn::Identity.new(token_with(locale: "en-US")).locale
end

test "extracting hd on google apps identity" do
assert_equal "basecamp.com", GoogleSignIn::Identity.new(g_suite_token_with(locale: "en-US")).hd
end
private
def switch_client_id_to(value)
previous_value = GoogleSignIn.client_id
Expand All @@ -73,4 +76,8 @@ def switch_client_id_to(value)
def token_with(aud: FAKE_GOOGLE_CLIENT_ID, iss: "https://accounts.google.com", key: GOOGLE_PRIVATE_KEY, **payload)
JWT.encode(payload.merge(aud: aud, iss: iss), key, "RS256")
end

def g_suite_token_with(aud: FAKE_GOOGLE_CLIENT_ID, iss: "https://accounts.google.com", key: GOOGLE_PRIVATE_KEY, **payload)
JWT.encode(payload.merge(aud: aud, iss: iss, hd: 'basecamp.com'), key, "RS256")
end
MattWalston marked this conversation as resolved.
Show resolved Hide resolved
end