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

feat(auth): Add enableAnonymousUser param to CreateTenant and UpdateTenant #412

Merged
merged 7 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 3 additions & 3 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error)
baseURL = fmt.Sprintf("http://%s/identitytoolkit.googleapis.com", authEmulatorHost)
}
idToolkitV1Endpoint := fmt.Sprintf("%s/v1", baseURL)
idToolkitV2Beta1Endpoint := fmt.Sprintf("%s/v2beta1", baseURL)
idToolkitV2Endpoint := fmt.Sprintf("%s/v2", baseURL)
userManagementEndpoint := idToolkitV1Endpoint
providerConfigEndpoint := idToolkitV2Beta1Endpoint
tenantMgtEndpoint := idToolkitV2Beta1Endpoint
providerConfigEndpoint := idToolkitV2Endpoint
tenantMgtEndpoint := idToolkitV2Endpoint

base := &baseClient{
userManagementEndpoint: userManagementEndpoint,
Expand Down
28 changes: 14 additions & 14 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import (
)

const (
credEnvVar = "GOOGLE_APPLICATION_CREDENTIALS"
testProjectID = "mock-project-id"
testVersion = "test-version"
defaultIDToolkitV1Endpoint = "https://identitytoolkit.googleapis.com/v1"
defaultIDToolkitV2Beta1Endpoint = "https://identitytoolkit.googleapis.com/v2beta1"
credEnvVar = "GOOGLE_APPLICATION_CREDENTIALS"
testProjectID = "mock-project-id"
testVersion = "test-version"
defaultIDToolkitV1Endpoint = "https://identitytoolkit.googleapis.com/v1"
defaultIDToolkitV2Endpoint = "https://identitytoolkit.googleapis.com/v2"
)

var (
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestNewClientExplicitNoAuth(t *testing.T) {
func TestNewClientEmulatorHostEnvVar(t *testing.T) {
emulatorHost := "localhost:9099"
idToolkitV1Endpoint := "http://localhost:9099/identitytoolkit.googleapis.com/v1"
idToolkitV2Beta1Endpoint := "http://localhost:9099/identitytoolkit.googleapis.com/v2beta1"
idToolkitV2Endpoint := "http://localhost:9099/identitytoolkit.googleapis.com/v2"

os.Setenv(emulatorHostEnvVar, emulatorHost)
defer os.Unsetenv(emulatorHostEnvVar)
Expand All @@ -305,11 +305,11 @@ func TestNewClientEmulatorHostEnvVar(t *testing.T) {
if baseClient.userManagementEndpoint != idToolkitV1Endpoint {
t.Errorf("baseClient.userManagementEndpoint = %q; want = %q", baseClient.userManagementEndpoint, idToolkitV1Endpoint)
}
if baseClient.providerConfigEndpoint != idToolkitV2Beta1Endpoint {
t.Errorf("baseClient.providerConfigEndpoint = %q; want = %q", baseClient.providerConfigEndpoint, idToolkitV2Beta1Endpoint)
if baseClient.providerConfigEndpoint != idToolkitV2Endpoint {
t.Errorf("baseClient.providerConfigEndpoint = %q; want = %q", baseClient.providerConfigEndpoint, idToolkitV2Endpoint)
}
if baseClient.tenantMgtEndpoint != idToolkitV2Beta1Endpoint {
t.Errorf("baseClient.tenantMgtEndpoint = %q; want = %q", baseClient.tenantMgtEndpoint, idToolkitV2Beta1Endpoint)
if baseClient.tenantMgtEndpoint != idToolkitV2Endpoint {
t.Errorf("baseClient.tenantMgtEndpoint = %q; want = %q", baseClient.tenantMgtEndpoint, idToolkitV2Endpoint)
}
if _, ok := baseClient.signer.(emulatedSigner); !ok {
t.Errorf("baseClient.signer = %#v; want = %#v", baseClient.signer, emulatedSigner{})
Expand Down Expand Up @@ -1427,11 +1427,11 @@ func checkBaseClient(client *Client, wantProjectID string) error {
if baseClient.userManagementEndpoint != defaultIDToolkitV1Endpoint {
return fmt.Errorf("userManagementEndpoint = %q; want = %q", baseClient.userManagementEndpoint, defaultIDToolkitV1Endpoint)
}
if baseClient.providerConfigEndpoint != defaultIDToolkitV2Beta1Endpoint {
return fmt.Errorf("providerConfigEndpoint = %q; want = %q", baseClient.providerConfigEndpoint, defaultIDToolkitV2Beta1Endpoint)
if baseClient.providerConfigEndpoint != defaultIDToolkitV2Endpoint {
return fmt.Errorf("providerConfigEndpoint = %q; want = %q", baseClient.providerConfigEndpoint, defaultIDToolkitV2Endpoint)
}
if baseClient.tenantMgtEndpoint != defaultIDToolkitV2Beta1Endpoint {
return fmt.Errorf("providerConfigEndpoint = %q; want = %q", baseClient.providerConfigEndpoint, defaultIDToolkitV2Beta1Endpoint)
if baseClient.tenantMgtEndpoint != defaultIDToolkitV2Endpoint {
return fmt.Errorf("providerConfigEndpoint = %q; want = %q", baseClient.providerConfigEndpoint, defaultIDToolkitV2Endpoint)
}
if baseClient.projectID != wantProjectID {
return fmt.Errorf("projectID = %q; want = %q", baseClient.projectID, wantProjectID)
Expand Down
12 changes: 12 additions & 0 deletions auth/tenant_mgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Tenant struct {
DisplayName string `json:"displayName"`
AllowPasswordSignUp bool `json:"allowPasswordSignup"`
EnableEmailLinkSignIn bool `json:"enableEmailLinkSignin"`
EnableAnonymousUsers bool `json:"enableAnonymousUser"`
}

// TenantClient is used for managing users, configuring SAML/OIDC providers, and generating email
Expand Down Expand Up @@ -216,6 +217,7 @@ const (
tenantDisplayNameKey = "displayName"
allowPasswordSignUpKey = "allowPasswordSignup"
enableEmailLinkSignInKey = "enableEmailLinkSignin"
enableAnonymousUser = "enableAnonymousUser"
)

// TenantToCreate represents the options used to create a new tenant.
Expand All @@ -240,6 +242,11 @@ func (t *TenantToCreate) EnableEmailLinkSignIn(enable bool) *TenantToCreate {
return t.set(enableEmailLinkSignInKey, enable)
}

// EnableAnonymousUsers enables or disables anonymous user.
lahirumaramba marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like EnableAnonymousUsers is a literal that should be backticked for code font.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like we back-tick literals in Go SDK. ex: TenantClient, AndroidNotification etc.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our auth docs use the term "anonymous authentication." Should that be used here?

I'd suggest that phrase, or, alternatively, "anonymous user access."

sonatard marked this conversation as resolved.
Show resolved Hide resolved
func (t *TenantToCreate) EnableAnonymousUsers(enable bool) *TenantToCreate {
return t.set(enableAnonymousUser, enable)
}

func (t *TenantToCreate) set(key string, value interface{}) *TenantToCreate {
t.ensureParams().Set(key, value)
return t
Expand Down Expand Up @@ -275,6 +282,11 @@ func (t *TenantToUpdate) EnableEmailLinkSignIn(enable bool) *TenantToUpdate {
return t.set(enableEmailLinkSignInKey, enable)
}

// EnableAnonymousUsers enables or disables anonymous user.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like EnableAnonymousUsers is a literal that should be backticked for code font.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our auth docs use the term "anonymous authentication." Should that be used here?

I'd suggest that phrase, or, alternatively, "anonymous user access."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, but in Go SDK we normally mention the function name followed by a description. Ex: AllowPasswordSignUp enables or disables email sign-in provider. or EnableEmailLinkSignIn enables or disables email link sign-in.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, OK, no backticks I could live with. But just "anonymous user" doesn't sound to me like a thing that can be enabled or disabled. Does it to you Lahiru?

I'd say that "email link sign-in" does sound like it can be disabled/enabled. FWIW at this point, "email sign-in provider" does not; "email sign-in provider support" or "email sign-in provider functionality" might.

This sounds like I'm splitting hairs, but one of the few things I bring to the table is an ear for written English. :) Let's get Kevin's input as well!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

"EnableAnonymousUsers enables or disables anonymous authentication."

(And FWIW, "AllowPasswordSignUp enables or disables the email sign-in provider.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 Yup, "the" solves that latter one!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I misread your previous comment, sorry! I understand what we are referring to now.
I am good with // EnableAnonymousUsers enables or disables anonymous user authentication.
Thank you!

sonatard marked this conversation as resolved.
Show resolved Hide resolved
func (t *TenantToUpdate) EnableAnonymousUsers(enable bool) *TenantToUpdate {
return t.set(enableAnonymousUser, enable)
}

func (t *TenantToUpdate) set(key string, value interface{}) *TenantToUpdate {
if t.params == nil {
t.params = make(nestedMap)
Expand Down
28 changes: 20 additions & 8 deletions auth/tenant_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,16 @@ const tenantResponse = `{
"name":"projects/mock-project-id/tenants/tenantID",
"displayName": "Test Tenant",
"allowPasswordSignup": true,
"enableEmailLinkSignin": true
"enableEmailLinkSignin": true,
"enableAnonymousUser": true
}`

const tenantResponse2 = `{
"name":"projects/mock-project-id/tenants/tenantID2",
"displayName": "Test Tenant 2",
"allowPasswordSignup": true,
"enableEmailLinkSignin": true
"enableEmailLinkSignin": true,
"enableAnonymousUser": true
}`

const tenantNotFoundResponse = `{
Expand All @@ -1105,13 +1107,15 @@ var testTenant = &Tenant{
DisplayName: "Test Tenant",
AllowPasswordSignUp: true,
EnableEmailLinkSignIn: true,
EnableAnonymousUsers: true,
}

var testTenant2 = &Tenant{
ID: "tenantID2",
DisplayName: "Test Tenant 2",
AllowPasswordSignUp: true,
EnableEmailLinkSignIn: true,
EnableAnonymousUsers: true,
}

func TestTenant(t *testing.T) {
Expand Down Expand Up @@ -1177,7 +1181,8 @@ func TestCreateTenant(t *testing.T) {
options := (&TenantToCreate{}).
DisplayName(testTenant.DisplayName).
AllowPasswordSignUp(testTenant.AllowPasswordSignUp).
EnableEmailLinkSignIn(testTenant.EnableEmailLinkSignIn)
EnableEmailLinkSignIn(testTenant.EnableEmailLinkSignIn).
EnableAnonymousUsers(testTenant.EnableAnonymousUsers)
tenant, err := client.TenantManager.CreateTenant(context.Background(), options)
if err != nil {
t.Fatal(err)
Expand All @@ -1191,6 +1196,7 @@ func TestCreateTenant(t *testing.T) {
"displayName": testTenant.DisplayName,
"allowPasswordSignup": testTenant.AllowPasswordSignUp,
"enableEmailLinkSignin": testTenant.EnableEmailLinkSignIn,
"enableAnonymousUser": testTenant.EnableAnonymousUsers,
}
if err := checkCreateTenantRequest(s, wantBody); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1225,7 +1231,8 @@ func TestCreateTenantZeroValues(t *testing.T) {
options := (&TenantToCreate{}).
DisplayName("").
AllowPasswordSignUp(false).
EnableEmailLinkSignIn(false)
EnableEmailLinkSignIn(false).
EnableAnonymousUsers(false)
tenant, err := client.TenantManager.CreateTenant(context.Background(), options)
if err != nil {
t.Fatal(err)
Expand All @@ -1239,6 +1246,7 @@ func TestCreateTenantZeroValues(t *testing.T) {
"displayName": "",
"allowPasswordSignup": false,
"enableEmailLinkSignin": false,
"enableAnonymousUser": false,
}
if err := checkCreateTenantRequest(s, wantBody); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1274,7 +1282,8 @@ func TestUpdateTenant(t *testing.T) {
options := (&TenantToUpdate{}).
DisplayName(testTenant.DisplayName).
AllowPasswordSignUp(testTenant.AllowPasswordSignUp).
EnableEmailLinkSignIn(testTenant.EnableEmailLinkSignIn)
EnableEmailLinkSignIn(testTenant.EnableEmailLinkSignIn).
EnableAnonymousUsers(testTenant.EnableAnonymousUsers)
tenant, err := client.TenantManager.UpdateTenant(context.Background(), "tenantID", options)
if err != nil {
t.Fatal(err)
Expand All @@ -1288,8 +1297,9 @@ func TestUpdateTenant(t *testing.T) {
"displayName": testTenant.DisplayName,
"allowPasswordSignup": testTenant.AllowPasswordSignUp,
"enableEmailLinkSignin": testTenant.EnableEmailLinkSignIn,
"enableAnonymousUser": testTenant.EnableAnonymousUsers,
}
wantMask := []string{"allowPasswordSignup", "displayName", "enableEmailLinkSignin"}
wantMask := []string{"allowPasswordSignup", "displayName", "enableAnonymousUser", "enableEmailLinkSignin"}
if err := checkUpdateTenantRequest(s, wantBody, wantMask); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1327,7 +1337,8 @@ func TestUpdateTenantZeroValues(t *testing.T) {
options := (&TenantToUpdate{}).
DisplayName("").
AllowPasswordSignUp(false).
EnableEmailLinkSignIn(false)
EnableEmailLinkSignIn(false).
EnableAnonymousUsers(false)
tenant, err := client.TenantManager.UpdateTenant(context.Background(), "tenantID", options)
if err != nil {
t.Fatal(err)
Expand All @@ -1341,8 +1352,9 @@ func TestUpdateTenantZeroValues(t *testing.T) {
"displayName": "",
"allowPasswordSignup": false,
"enableEmailLinkSignin": false,
"enableAnonymousUser": false,
}
wantMask := []string{"allowPasswordSignup", "displayName", "enableEmailLinkSignin"}
wantMask := []string{"allowPasswordSignup", "displayName", "enableAnonymousUser", "enableEmailLinkSignin"}
if err := checkUpdateTenantRequest(s, wantBody, wantMask); err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 6 additions & 2 deletions integration/auth/tenant_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ func TestTenantManager(t *testing.T) {
DisplayName: "admin-go-tenant",
AllowPasswordSignUp: true,
EnableEmailLinkSignIn: true,
EnableAnonymousUsers: true,
}

req := (&auth.TenantToCreate{}).
DisplayName("admin-go-tenant").
AllowPasswordSignUp(true).
EnableEmailLinkSignIn(true)
EnableEmailLinkSignIn(true).
EnableAnonymousUsers(true)
created, err := client.TenantManager.CreateTenant(context.Background(), req)
if err != nil {
t.Fatalf("CreateTenant() = %v", err)
Expand Down Expand Up @@ -129,11 +131,13 @@ func TestTenantManager(t *testing.T) {
DisplayName: "updated-go-tenant",
AllowPasswordSignUp: false,
EnableEmailLinkSignIn: false,
EnableAnonymousUsers: false,
}
req := (&auth.TenantToUpdate{}).
DisplayName("updated-go-tenant").
AllowPasswordSignUp(false).
EnableEmailLinkSignIn(false)
EnableEmailLinkSignIn(false).
EnableAnonymousUsers(false)
tenant, err := client.TenantManager.UpdateTenant(context.Background(), id, req)
if err != nil {
t.Fatalf("UpdateTenant() = %v", err)
Expand Down