mirror of
https://github.com/google/nomulus.git
synced 2025-05-19 18:59:35 +02:00
Configure client id and client secret in the config file
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=224158599
This commit is contained in:
parent
6352b8a01a
commit
5f9aad90fc
10 changed files with 41 additions and 82 deletions
|
@ -21,6 +21,7 @@ import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInsta
|
|||
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.Details;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.client.util.store.AbstractDataStoreFactory;
|
||||
|
@ -38,7 +39,6 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -91,20 +91,21 @@ public class AuthModule {
|
|||
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver());
|
||||
}
|
||||
|
||||
@Provides
|
||||
static Details provideDefaultInstalledDetails() {
|
||||
return new Details()
|
||||
.setAuthUri("https://accounts.google.com/o/oauth2/auth")
|
||||
.setTokenUri("https://accounts.google.com/o/oauth2/token")
|
||||
.setRedirectUris(ImmutableList.of("urn:ietf:wg:oauth:2.0:oob", "http://localhost"));
|
||||
}
|
||||
|
||||
@Provides
|
||||
public static GoogleClientSecrets provideClientSecrets(
|
||||
@Config("clientSecretFilename") String clientSecretFilename, JsonFactory jsonFactory) {
|
||||
try {
|
||||
// Load the client secrets file.
|
||||
InputStream secretResourceStream = AuthModule.class.getResourceAsStream(clientSecretFilename);
|
||||
if (secretResourceStream == null) {
|
||||
throw new RuntimeException("No client secret file found: " + clientSecretFilename);
|
||||
}
|
||||
return GoogleClientSecrets.load(jsonFactory,
|
||||
new InputStreamReader(secretResourceStream, UTF_8));
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
@Config("toolsClientId") String clientId,
|
||||
@Config("toolsClientSecret") String clientSecret,
|
||||
Details details) {
|
||||
return new GoogleClientSecrets()
|
||||
.setInstalled(details.setClientId(clientId).setClientSecret(clientSecret));
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -26,11 +26,6 @@ java_library(
|
|||
resources = glob([
|
||||
"*.properties",
|
||||
"sql/*.sql",
|
||||
|
||||
# These are example client secret files. You'll need to obtain your
|
||||
# own for every environment you use and install them in this
|
||||
# directory.
|
||||
"resources/client_secret*.json",
|
||||
]),
|
||||
visibility = [":allowed-tools"],
|
||||
runtime_deps = [
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
# Adding Client Secrets
|
||||
|
||||
This directory contains the client secret files needed by the `nomulus` tool to
|
||||
connect to the Nomulus backend via OAuth2. Adding client secret files to this
|
||||
directory is one of two steps you need to perform; the other is adding the
|
||||
client id contained in the client secret file to the list of allowed ids in the
|
||||
Nomulus configuration file. See the configuration documentation for more
|
||||
information.
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"installed": {
|
||||
"client_id":"SEE-README.md-IN_THIS_DIRECTORY.apps.googleusercontent.com",
|
||||
"project_id":"your-registry-server",
|
||||
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri":"https://accounts.google.com/o/oauth2/token",
|
||||
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_secret":"YOUR-CLIENT-SECRET",
|
||||
"redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"installed": {
|
||||
"client_id":"UNITTEST-CLIENT-ID",
|
||||
"project_id":"DO NOT CHANGE",
|
||||
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri":"https://accounts.google.com/o/oauth2/token",
|
||||
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_secret":"UNITTEST-CLIENT-SECRET",
|
||||
"redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue