All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nitorcreations.willow.auth.GitHubOAuthConfig Maven / Gradle / Ivy

The newest version!
package com.nitorcreations.willow.auth;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.Properties;

import com.google.inject.ConfigurationException;
import com.google.inject.spi.Message;

public class GitHubOAuthConfig {
  private final String redirectUri;
  private final String clientId;
  private final String clientSecret;
  private final String organization;
  private final String adminTeam;
  
  public GitHubOAuthConfig(String redirectUri, String clientId, String clientSecret, String organization, String adminTeam) {
    this.redirectUri = redirectUri;
    this.clientId = clientId;
    this.clientSecret = clientSecret;
    this.organization = organization;
    this.adminTeam = adminTeam;
  }
  public static GitHubOAuthConfig fromUrl(String url) throws ConfigurationException {
    try (InputStream in = new URL(url).openStream()){
      Properties config = new Properties();
      config.load(in);
      String redirectUri = config.getProperty("redirect_uri", "");
      String clientId = config.getProperty("client_id", "");
      String clientSecret = config.getProperty("client_secret", "");
      String organization = config.getProperty("organization", "");
      String adminTeam = config.getProperty("admin_team", "");
      return new GitHubOAuthConfig(redirectUri, clientId, clientSecret, organization, adminTeam);
    } catch (IOException e) {
      throw new ConfigurationException(Arrays.asList(new Message("Failed to read GitHub OAuth config"), new Message(e.getMessage())));
    }
  }
  public String getRedirectUri() {
    return redirectUri;
  }
  public String getClientId() {
    return clientId;
  }
  public String getClientSecret() {
    return clientSecret;
  }
  public String getOrganization() {
    return organization;
  }
  public String getAdminTeam() {
    return adminTeam;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy