Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding scope to fix the start up issue #68

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions custom-config-server-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<artifactId>azure</artifactId>
<version>1.34.0</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.6.0</version> <!-- Use the version compatible with your project -->
</dependency>

<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -45,9 +50,8 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.3.0</version>
<version>1.37.0</version>
</dependency>

<!-- tag::actuator[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -61,6 +65,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.8.1</version>
</dependency>

<!-- end::tests[] -->
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,38 @@

package com.microsoft.sample.customConfigServerClient;

import com.azure.core.credential.TokenRequestContext;
import com.azure.identity.ClientSecretCredential;
import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import com.azure.identity.ClientSecretCredentialBuilder;

public class AccessTokenManager {

private static String token;
static {
Properties prop = new Properties();
InputStream in = AccessTokenManager.class.getResourceAsStream("/application.properties");
try {
prop.load(in);
tokenClientId = prop.getProperty("access.token.clientId");
String tenantId = prop.getProperty("access.token.tenantId");
String secret = prop.getProperty("access.token.secret");
String clientId = prop.getProperty("access.token.clientId");
credentials = new ApplicationTokenCredentials(
clientId, tenantId, secret, AzureEnvironment.AZURE);
ClientSecretCredential credential = new ClientSecretCredentialBuilder()
.clientId(clientId)
.clientSecret(secret)
.tenantId(tenantId)
.authorityHost(AzureEnvironment.AZURE.activeDirectoryEndpoint())
.build();
TokenRequestContext tokenRequest = new TokenRequestContext().addScopes("https://management.core.windows.net//.default");
token = credential.getToken(tokenRequest).block().getToken();
} catch (IOException e) {
System.err.println(e.getMessage());
}
}

private static String tokenClientId;

private static ApplicationTokenCredentials credentials;

public static String getToken() throws IOException {
return credentials.getToken(tokenClientId);
return token;
}
}