Skip to content

Commit 4d13b23

Browse files
committed
Tweak provider config classes so that CreateRequest can be properly chained.
1 parent c5f3917 commit 4d13b23

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

src/main/java/com/google/firebase/auth/AuthProviderConfig.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,24 @@
2929
*/
3030
public abstract class AuthProviderConfig {
3131

32-
@Key("name")
32+
// Lazily initialized from 'resourceName'.
3333
private String providerId;
3434

35+
@Key("name")
36+
private String resourceName;
37+
3538
@Key("displayName")
3639
private String displayName;
3740

3841
@Key("enabled")
3942
private boolean enabled;
4043

44+
// TODO(micahstairs): Add unit test for this.
45+
// Example: projects/388188666963/oauthIdpConfigs/oidc.config-id
4146
public String getProviderId() {
47+
if (providerId == null) {
48+
providerId = resourceName.substring(resourceName.lastIndexOf("/") + 1);
49+
}
4250
return providerId;
4351
}
4452

@@ -56,45 +64,53 @@ public boolean isEnabled() {
5664
* <p>Set the initial attributes of the new provider by calling various setter methods available
5765
* in this class.
5866
*/
59-
public abstract static class CreateRequest {
67+
public abstract static class CreateRequest<T extends CreateRequest<T>> {
6068

6169
final Map<String,Object> properties = new HashMap<>();
70+
String providerId;
6271

6372
/**
64-
* Sets the ID for the new provider.
73+
* Sets the display name for the new provider.
6574
*
6675
* @param providerId a non-null, non-empty provider ID string.
6776
*/
68-
public CreateRequest setProviderId(String providerId) {
77+
public T setProviderId(String providerId) {
6978
checkArgument(
7079
!Strings.isNullOrEmpty(providerId), "provider ID name must not be null or empty");
71-
properties.put("name", providerId);
72-
return this;
80+
this.providerId = providerId;
81+
return getThis();
82+
}
83+
84+
// TODO(micahstairs): Add a unit test for this method.
85+
String getProviderId() {
86+
return providerId;
7387
}
7488

7589
/**
7690
* Sets the display name for the new provider.
7791
*
7892
* @param displayName a non-null, non-empty display name string.
7993
*/
80-
public CreateRequest setDisplayName(String displayName) {
94+
public T setDisplayName(String displayName) {
8195
checkArgument(!Strings.isNullOrEmpty(displayName), "display name must not be null or empty");
8296
properties.put("displayName", displayName);
83-
return this;
97+
return getThis();
8498
}
8599

86100
/**
87-
* Sets whether to allow the user to sign in with the provider..
101+
* Sets whether to allow the user to sign in with the provider.
88102
*
89103
* @param enabled a boolean indicating whether the user can sign in with the provider
90104
*/
91-
public CreateRequest setEnabled(boolean enabled) {
105+
public T setEnabled(boolean enabled) {
92106
properties.put("enabled", enabled);
93-
return this;
107+
return getThis();
94108
}
95109

96110
Map<String, Object> getProperties() {
97111
return ImmutableMap.copyOf(properties);
98112
}
113+
114+
abstract T getThis();
99115
}
100116
}

src/main/java/com/google/firebase/auth/OidcProviderConfig.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public String getIssuer() {
5151
* <p>Set the initial attributes of the new provider by calling various setter methods available
5252
* in this class.
5353
*/
54-
public static final class CreateRequest extends AuthProviderConfig.CreateRequest {
54+
public static final class CreateRequest extends AuthProviderConfig.CreateRequest<CreateRequest> {
5555

5656
/**
5757
* Creates a new {@link CreateRequest}, which can be used to create a new OIDC Auth provider.
5858
*
5959
* <p>The returned object should be passed to
60-
* {@link TenantAwareFirebaseAuth#createProviderConfig(CreateRequest)} to register the provider
60+
* {@link AbstractFirebaseAuth#createProviderConfig(CreateRequest)} to register the provider
6161
* information persistently.
6262
*/
6363
public CreateRequest() { }
@@ -83,5 +83,9 @@ public CreateRequest setIssuer(String issuer) {
8383
properties.put("issuer", issuer);
8484
return this;
8585
}
86+
87+
CreateRequest getThis() {
88+
return this;
89+
}
8690
}
8791
}

0 commit comments

Comments
 (0)