mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-01-09 19:10:29 +05:30
Better Error handling for oidc config
This commit is contained in:
parent
604fa651fc
commit
375ee585c1
@ -84,4 +84,6 @@ hibernate.connection.password:changeme
|
||||
#oidc.provider.INSERT_HERE.name:INSERT_HERE
|
||||
#oidc.provider.INSERT_HERE.clientId:INSERT_HERE
|
||||
#oidc.provider.INSERT_HERE.clientSecret:INSERT_HERE
|
||||
#oidc.provider.INSERT_HERE.authUrl:INSERT_HERE
|
||||
#oidc.provider.INSERT_HERE.authUri:INSERT_HERE
|
||||
#oidc.provider.INSERT_HERE.tokenUri:INSERT_HERE
|
||||
#oidc.provider.INSERT_HERE.userinfoUri:INSERT_HERE
|
@ -26,7 +26,7 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ProxySelector;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Pattern;
|
||||
@ -102,7 +102,7 @@ public class Constants {
|
||||
public static final String YOUTUBE_COUNTRY;
|
||||
|
||||
public static final String VERSION;
|
||||
public static final LinkedList<OidcProvider> OIDC_PROVIDERS;
|
||||
public static final ArrayList<OidcProvider> OIDC_PROVIDERS;
|
||||
|
||||
public static final ObjectMapper mapper = JsonMapper.builder()
|
||||
.addMixIn(Page.class, PageMixin.class)
|
||||
@ -167,7 +167,7 @@ public class Constants {
|
||||
MATRIX_TOKEN = getProperty(prop, "MATRIX_TOKEN");
|
||||
GEO_RESTRICTION_CHECKER_URL = getProperty(prop, "GEO_RESTRICTION_CHECKER_URL");
|
||||
|
||||
OIDC_PROVIDERS = new LinkedList<>();
|
||||
OIDC_PROVIDERS = new ArrayList<>();
|
||||
ArrayNode providerNames = frontendProperties.putArray("oidcProviders");
|
||||
prop.forEach((_key, _value) -> {
|
||||
String key = String.valueOf(_key), value = String.valueOf(_value);
|
||||
@ -178,20 +178,14 @@ public class Constants {
|
||||
else if (key.startsWith("oidc.provider")) {
|
||||
String[] split = key.split("\\.");
|
||||
if (split.length != 4 || !split[3].equals("name")) return;
|
||||
|
||||
try {
|
||||
OIDC_PROVIDERS.add(new OidcProvider(
|
||||
value,
|
||||
getProperty(prop, "oidc.provider." + value + ".clientId"),
|
||||
getProperty(prop, "oidc.provider." + value + ".clientSecret"),
|
||||
getProperty(prop, "oidc.provider." + value + ".authUrl"),
|
||||
getProperty(prop, "oidc.provider." + value + ".tokenUrl"),
|
||||
getProperty(prop, "oidc.provider." + value + ".userinfoUrl")
|
||||
));
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while getting properties for oidc provider '" + value + "'");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
getRequiredOidcProperty(prop, value, "clientId"),
|
||||
getRequiredOidcProperty(prop, value, "clientSecret"),
|
||||
getRequiredOidcProperty(prop, value, "authUri"),
|
||||
getRequiredOidcProperty(prop, value, "tokenUri"),
|
||||
getRequiredOidcProperty(prop, value, "userinfoUri"))
|
||||
);
|
||||
providerNames.add(value);
|
||||
}
|
||||
});
|
||||
@ -256,4 +250,13 @@ public class Constants {
|
||||
|
||||
return prop.getProperty(key, def);
|
||||
}
|
||||
|
||||
private static String getRequiredOidcProperty(final Properties prop, String provider, String key) {
|
||||
String value = getProperty(prop, "oidc.provider." + provider + "." + key);
|
||||
if(value == null || value.equals("")){
|
||||
System.err.println("Missing " + key + " for oidc provider '" + provider + "'");
|
||||
System.exit(1);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,17 @@ public class OidcProvider {
|
||||
public URI tokenUri;
|
||||
public URI userinfoUri;
|
||||
|
||||
public OidcProvider(String name, String clientID, String clientSecret, String authUri, String tokenUri, String userinfoUri) throws URISyntaxException {
|
||||
public OidcProvider(String name, String clientID, String clientSecret, String authUri, String tokenUri, String userinfoUri) {
|
||||
this.name = name;
|
||||
this.clientID = new ClientID(clientID);
|
||||
this.clientSecret = new Secret(clientSecret);
|
||||
try {
|
||||
this.authUri = new URI(authUri);
|
||||
this.tokenUri = new URI(tokenUri);
|
||||
this.userinfoUri = new URI(userinfoUri);
|
||||
} catch(URISyntaxException e) {
|
||||
System.err.println("Malformed URI for oidc provider '" + name + "' found.");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user