Skip to content

Commit ad3f172

Browse files
committed
feat(oauth2): expose scopes in authentication metadata API response
Adds OAuth2Values class to AuthenticationMetaDataResponseV1 that exposes clientId, baseUrl, and scopes from OAuth2AuthenticationMetaData. Closes #374
1 parent b02c37a commit ad3f172

File tree

2 files changed

+124
-7
lines changed

2 files changed

+124
-7
lines changed

qqq-middleware-javalin/src/main/java/com/kingsrook/qqq/middleware/javalin/specs/v1/responses/AuthenticationMetaDataResponseV1.java

Lines changed: 123 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424

2525
import com.kingsrook.qqq.backend.core.model.metadata.authentication.Auth0AuthenticationMetaData;
26+
import com.kingsrook.qqq.backend.core.model.metadata.authentication.OAuth2AuthenticationMetaData;
2627
import com.kingsrook.qqq.backend.core.model.metadata.authentication.QAuthenticationMetaData;
2728
import com.kingsrook.qqq.middleware.javalin.executors.io.AuthenticationMetaDataOutputInterface;
2829
import com.kingsrook.qqq.middleware.javalin.schemabuilder.ToSchema;
@@ -60,7 +61,7 @@ may be needed to complete the authorization workflow with the provider (e.g., a
6061
/***************************************************************************
6162
**
6263
***************************************************************************/
63-
public sealed interface Values permits EmptyValues, Auth0Values
64+
public sealed interface Values permits EmptyValues, Auth0Values, OAuth2Values
6465
{
6566

6667
}
@@ -199,6 +200,118 @@ public Auth0Values withAudience(String audience)
199200

200201

201202

203+
/***************************************************************************
204+
**
205+
***************************************************************************/
206+
@OpenAPIDescription("Additional values used by the OAuth2 type authentication provider.")
207+
public static final class OAuth2Values implements Values
208+
{
209+
@OpenAPIDescription("ClientId for OAuth2 provider")
210+
private String clientId;
211+
212+
@OpenAPIDescription("BaseUrl for OAuth2 provider")
213+
private String baseUrl;
214+
215+
@OpenAPIDescription("OAuth2 scopes to request (space-separated)")
216+
private String scopes;
217+
218+
219+
220+
/*******************************************************************************
221+
** Getter for clientId
222+
*******************************************************************************/
223+
public String getClientId()
224+
{
225+
return clientId;
226+
}
227+
228+
229+
230+
/*******************************************************************************
231+
** Setter for clientId
232+
*******************************************************************************/
233+
public void setClientId(String clientId)
234+
{
235+
this.clientId = clientId;
236+
}
237+
238+
239+
240+
/*******************************************************************************
241+
** Fluent setter for clientId
242+
*******************************************************************************/
243+
public OAuth2Values withClientId(String clientId)
244+
{
245+
this.clientId = clientId;
246+
return (this);
247+
}
248+
249+
250+
251+
/*******************************************************************************
252+
** Getter for baseUrl
253+
*******************************************************************************/
254+
public String getBaseUrl()
255+
{
256+
return baseUrl;
257+
}
258+
259+
260+
261+
/*******************************************************************************
262+
** Setter for baseUrl
263+
*******************************************************************************/
264+
public void setBaseUrl(String baseUrl)
265+
{
266+
this.baseUrl = baseUrl;
267+
}
268+
269+
270+
271+
/*******************************************************************************
272+
** Fluent setter for baseUrl
273+
*******************************************************************************/
274+
public OAuth2Values withBaseUrl(String baseUrl)
275+
{
276+
this.baseUrl = baseUrl;
277+
return (this);
278+
}
279+
280+
281+
282+
/*******************************************************************************
283+
** Getter for scopes
284+
*******************************************************************************/
285+
public String getScopes()
286+
{
287+
return scopes;
288+
}
289+
290+
291+
292+
/*******************************************************************************
293+
** Setter for scopes
294+
*******************************************************************************/
295+
public void setScopes(String scopes)
296+
{
297+
this.scopes = scopes;
298+
}
299+
300+
301+
302+
/*******************************************************************************
303+
** Fluent setter for scopes
304+
*******************************************************************************/
305+
public OAuth2Values withScopes(String scopes)
306+
{
307+
this.scopes = scopes;
308+
return (this);
309+
}
310+
311+
}
312+
313+
314+
202315
/***************************************************************************
203316
**
204317
***************************************************************************/
@@ -208,12 +321,16 @@ public void setAuthenticationMetaData(QAuthenticationMetaData qAuthenticationMet
208321
setType(qAuthenticationMetaData.getType().name());
209322
setName(qAuthenticationMetaData.getName());
210323

211-
if(qAuthenticationMetaData instanceof Auth0AuthenticationMetaData auth0MetaData)
324+
if(qAuthenticationMetaData instanceof OAuth2AuthenticationMetaData oauth2MetaData)
325+
{
326+
OAuth2Values oauth2Values = new OAuth2Values();
327+
values = oauth2Values;
328+
oauth2Values.setClientId(oauth2MetaData.getClientId());
329+
oauth2Values.setBaseUrl(oauth2MetaData.getBaseUrl());
330+
oauth2Values.setScopes(oauth2MetaData.getScopes());
331+
}
332+
else if(qAuthenticationMetaData instanceof Auth0AuthenticationMetaData auth0MetaData)
212333
{
213-
// values = new LinkedHashMap<>();
214-
// values.put("clientId", auth0MetaData.getClientId());
215-
// values.put("baseUrl", auth0MetaData.getBaseUrl());
216-
// values.put("audience", auth0MetaData.getAudience());
217334
Auth0Values auth0Values = new Auth0Values();
218335
values = auth0Values;
219336
auth0Values.setClientId(auth0MetaData.getClientId());

qqq-middleware-javalin/src/test/java/com/kingsrook/qqq/middleware/javalin/schemabuilder/SchemaBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void testIncludesAOneOf()
5151

5252
Schema valuesSchema = schema.getProperties().get("values");
5353
List<Schema> oneOf = valuesSchema.getOneOf();
54-
assertEquals(2, oneOf.size());
54+
assertEquals(3, oneOf.size());
5555
}
5656

5757

0 commit comments

Comments
 (0)