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 given name and family name to identity functions #25

Merged
merged 2 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ information contained in the token via the following instance methods:

* `hosted_domain`: The user’s hosted G Suite domain, provided only if they belong to a G Suite.

* `given_name`: The user's given name.

* `last_name`: The user's last name.


## Security

Expand Down
8 changes: 8 additions & 0 deletions lib/google_sign_in/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def hosted_domain
@payload["hd"]
end

def given_name
@payload["given_name"]
end

def family_name
@payload["family_name"]
end

private
delegate :client_id, to: GoogleSignIn

Expand Down
8 changes: 8 additions & 0 deletions test/models/identity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class GoogleSignIn::IdentityTest < ActiveSupport::TestCase
assert_equal "basecamp.com", GoogleSignIn::Identity.new(token_with(hd: "basecamp.com")).hosted_domain
end

test "extracting given name" do
assert_equal "George", GoogleSignIn::Identity.new(token_with(given_name: "George")).given_name
end

test "extracting family name" do
assert_equal "Claghorn", GoogleSignIn::Identity.new(token_with(family_name: "Claghorn")).family_name
end

private
def switch_client_id_to(value)
previous_value = GoogleSignIn.client_id
Expand Down