Example usage for com.google.api.client.googleapis.testing.auth.oauth2 MockTokenServerTransport addServiceAccount

List of usage examples for com.google.api.client.googleapis.testing.auth.oauth2 MockTokenServerTransport addServiceAccount

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.testing.auth.oauth2 MockTokenServerTransport addServiceAccount.

Prototype

public void addServiceAccount(String email, String accessToken) 

Source Link

Usage

From source file:com.netflix.spinnaker.igor.gcb.GoogleCloudBuildTestConfig.java

License:Apache License

@Bean
@Primary//from w  w w  .ja  v  a  2  s  . c  om
GoogleCredentialService googleCredentialService() {
    return new GoogleCredentialService() {
        @Override
        GoogleCredential getFromKey(String jsonPath) {
            if (!jsonPath.equals("/path/to/some/file")) {
                return null;
            }
            // Create a mock credential whose bearer token is always "test-token"
            try {
                InputStream is = GoogleCloudBuildAccountFactory.class
                        .getResourceAsStream("/gcb/gcb-test-account.json");
                MockTokenServerTransport mockTransport = new MockTokenServerTransport(
                        "https://accounts.google.com/o/oauth2/auth");
                mockTransport.addServiceAccount("test-account@spinnaker-gcb-test.iam.gserviceaccount.com",
                        "test-token");
                return GoogleCredential.fromStream(is, mockTransport, JacksonFactory.getDefaultInstance())
                        .createScoped(CloudBuildScopes.all());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    };
}