Skip to content

Commit c5f3917

Browse files
committed
Add OIDC provider config class and base class.
1 parent e7415da commit c5f3917

File tree

2 files changed

+187
-0
lines changed

2 files changed

+187
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.auth;
18+
19+
import static com.google.common.base.Preconditions.checkArgument;
20+
21+
import com.google.api.client.util.Key;
22+
import com.google.common.base.Strings;
23+
import com.google.common.collect.ImmutableMap;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
27+
/**
28+
* The base class for Auth providers.
29+
*/
30+
public abstract class AuthProviderConfig {
31+
32+
@Key("name")
33+
private String providerId;
34+
35+
@Key("displayName")
36+
private String displayName;
37+
38+
@Key("enabled")
39+
private boolean enabled;
40+
41+
public String getProviderId() {
42+
return providerId;
43+
}
44+
45+
public String getDisplayName() {
46+
return displayName;
47+
}
48+
49+
public boolean isEnabled() {
50+
return enabled;
51+
}
52+
53+
/**
54+
* A base specification class for creating a new provider.
55+
*
56+
* <p>Set the initial attributes of the new provider by calling various setter methods available
57+
* in this class.
58+
*/
59+
public abstract static class CreateRequest {
60+
61+
final Map<String,Object> properties = new HashMap<>();
62+
63+
/**
64+
* Sets the ID for the new provider.
65+
*
66+
* @param providerId a non-null, non-empty provider ID string.
67+
*/
68+
public CreateRequest setProviderId(String providerId) {
69+
checkArgument(
70+
!Strings.isNullOrEmpty(providerId), "provider ID name must not be null or empty");
71+
properties.put("name", providerId);
72+
return this;
73+
}
74+
75+
/**
76+
* Sets the display name for the new provider.
77+
*
78+
* @param displayName a non-null, non-empty display name string.
79+
*/
80+
public CreateRequest setDisplayName(String displayName) {
81+
checkArgument(!Strings.isNullOrEmpty(displayName), "display name must not be null or empty");
82+
properties.put("displayName", displayName);
83+
return this;
84+
}
85+
86+
/**
87+
* Sets whether to allow the user to sign in with the provider..
88+
*
89+
* @param enabled a boolean indicating whether the user can sign in with the provider
90+
*/
91+
public CreateRequest setEnabled(boolean enabled) {
92+
properties.put("enabled", enabled);
93+
return this;
94+
}
95+
96+
Map<String, Object> getProperties() {
97+
return ImmutableMap.copyOf(properties);
98+
}
99+
}
100+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.auth;
18+
19+
import static com.google.common.base.Preconditions.checkArgument;
20+
21+
import com.google.api.client.util.Key;
22+
import com.google.common.base.Strings;
23+
import com.google.common.collect.ImmutableMap;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
27+
/**
28+
* Contains metadata associated with an OIDC Auth provider.
29+
*
30+
* <p>Instances of this class are immutable and thread safe.
31+
*/
32+
public final class OidcProviderConfig extends AuthProviderConfig {
33+
34+
@Key("clientId")
35+
private String clientId;
36+
37+
@Key("issuer")
38+
private String issuer;
39+
40+
public String getClientId() {
41+
return clientId;
42+
}
43+
44+
public String getIssuer() {
45+
return issuer;
46+
}
47+
48+
/**
49+
* A specification class for creating a new OIDC Auth provider.
50+
*
51+
* <p>Set the initial attributes of the new provider by calling various setter methods available
52+
* in this class.
53+
*/
54+
public static final class CreateRequest extends AuthProviderConfig.CreateRequest {
55+
56+
/**
57+
* Creates a new {@link CreateRequest}, which can be used to create a new OIDC Auth provider.
58+
*
59+
* <p>The returned object should be passed to
60+
* {@link TenantAwareFirebaseAuth#createProviderConfig(CreateRequest)} to register the provider
61+
* information persistently.
62+
*/
63+
public CreateRequest() { }
64+
65+
/**
66+
* Sets the client ID for the new provider.
67+
*
68+
* @param clientId a non-null, non-empty client ID string.
69+
*/
70+
public CreateRequest setClientId(String clientId) {
71+
checkArgument(!Strings.isNullOrEmpty(clientId), "client ID must not be null or empty");
72+
properties.put("clientId", clientId);
73+
return this;
74+
}
75+
76+
/**
77+
* Sets the issuer for the new provider.
78+
*
79+
* @param issuer a non-null, non-empty issuer string.
80+
*/
81+
public CreateRequest setIssuer(String issuer) {
82+
checkArgument(!Strings.isNullOrEmpty(issuer), "issuer must not be null or empty");
83+
properties.put("issuer", issuer);
84+
return this;
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)