public static StructrOAuthClient getServer ( final String name ) { String configuredOauthServers = Settings . OAuthServers . getValue ( ) ; String [ ] authServers = configuredOauthServers . split ( " " ) ; for ( String authServer : authServers ) { if ( authServer . equals ( name ) ) { String authLocation = Settings . getOrCreateStringSetting ( "oauth" , authServer , "authorization_location" ) . getValue ( "" ) ; String tokenLocation = Settings . getOrCreateStringSetting ( "oauth" , authServer , "token_location" ) . getValue ( "" ) ; String clientId = Settings . getOrCreateStringSetting ( "oauth" , authServer , "client_id" ) . getValue ( "" ) ; String clientSecret = Settings . getOrCreateStringSetting ( "oauth" , authServer , "client_secret" ) . getValue ( "" ) ; String redirectUri = Settings . getOrCreateStringSetting ( "oauth" , authServer , "redirect_uri" ) . getValue ( "" ) ; // Minumum required fields if ( clientId != null && clientSecret != null && redirectUri != null ) { Class serverClass = getServerClassForName ( name ) ; Class tokenResponseClass = getTokenResponseClassForName ( name ) ; if ( serverClass != null ) { StructrOAuthClient oauthServer ; try { oauthServer = ( StructrOAuthClient ) serverClass . newInstance ( ) ; oauthServer . init ( authLocation , tokenLocation , clientId , clientSecret , redirectUri , tokenResponseClass ) ; logger . info ( "Using OAuth server {}" , oauthServer ) ; return oauthServer ; } catch ( Throwable t ) { logger . error ( "Could not instantiate auth server" , t ) ; } } else { logger . warn ( "No OAuth provider found for name {}, ignoring." , name ) ; } } } } return null ; }
Build an OAuth2 server from the configured values for the given name .