GraphServiceClient does not use authentication provider
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- azure, java, spring-boot
- Lĩnh vực
- api, authentication, backend
Hướng nghiên cứu
Bắt đầu với việc khởi tạo GraphServiceClient(authProvider, httpClient) và theo dõi cách AzureIdentityAuthenticationProvider được áp dụng khi GraphClientFactory.create().proxy(proxy).build() cung cấp HTTP client. Tái hiện cấu hình proxy đã cung cấp và so sánh với phương án interceptor đang hoạt động. Hoàn thành khi authentication provider cung cấp header Authorization mà không cần workaround.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Describe the bug
Copying this bug from here as it seems to be an graph sdk issue:
I am using the following code to instantiate a GraphServiceClient. As I require to configure a http proxy I followed this example, see alternative 1 in code. Doing so the client will not aquire a token from the AuthenticationProvider and fails to connect, see Exception or Stack Trace.
Enforcing an Authorization header in the http client will fix the problem, see alternative 2.
Exception or Stack Trace
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getGraphClient' defined in class path resource [xxxxxxxxxxxxxxxxx.class]: Failed to instantiate [com.microsoft.graph.serviceclient.GraphServiceClient]: Factory method 'getGraphClient' threw exception with message: Access token is empty.
To Reproduce
n.a.
Code Snippet
assert (tenantId != null) : "Env var AZURE_TENANT_ID has not been provided.";
assert (clientId != null) : "Env var AZURE_CLIENT_ID has not been provided.";
assert (clientSecret != null) : "Env var AZURE_CLIENT_SECRET has not been provided.";
assert (proxyHost != null) : "Env var PROXY_HOST has not been provided";
assert (proxyPort != null) : "Env var PROXY_PORT has not been provided";
logger.debug("tenant {}", tenantId);
logger.debug("clientId {}", clientId);
logger.debug("proxyHost {}", proxyHost);
logger.debug("proxyPort {}", proxyPort);
int proxyPortInt=0;
try {
proxyPortInt = Integer.parseInt(proxyPort);
} catch (NumberFormatException e) {
assert (false) : "Proxy port is not a valid integer";
}
// Example code taken from https://docs.microsoft.com/en-us/graph/sdks/customize-client?tabs=java#configuring-the-http-proxy-for-the-client
InetSocketAddress address = new InetSocketAddress(proxyHost, proxyPortInt);
ProxyOptions options = new ProxyOptions(ProxyOptions.Type.HTTP, address);
HttpClient authClient = new NettyAsyncHttpClientBuilder().proxy(options)
.build();
ClientSecretCredential credential = new ClientSecretCredentialBuilder()
.clientId(clientId)
.tenantId(tenantId)
.clientSecret(clientSecret)
.httpClient(authClient)
.build();
String[] scopes = new String[]{"User.Read.All", "GroupMember.Read.All"};
AzureIdentityAuthenticationProvider authProvider =
new AzureIdentityAuthenticationProvider(credential, List.of("login.microsoftonline.com").toArray(new String[0]), scopes);
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
// Alternative 2: It works with this code uncommented
//
// OkHttpClient httpClient = GraphClientFactory.create().addInterceptor(chain -> {
// Request originalRequest = chain.request();
//
// // Get the access token
// String accessToken = Objects.requireNonNull(credential.getToken(
// new TokenRequestContext()
// .addScopes("https://graph.microsoft.com/.default"))
// .block())
// .getToken();
//
// // Add Authorization header
// Request authenticatedRequest = originalRequest.newBuilder()
// .header("Authorization", "Bearer " + accessToken)
// .build();
//
// return chain.proceed(authenticatedRequest);
// }).proxy(proxy).build();
// Alternative 2 end
// Alternative 1: It should work with this code (comment if uncommenting block above!
OkHttpClient httpClient = GraphClientFactory.create().proxy(proxy).build();
// Alternative 1 end
GraphServiceClient graphClient = new GraphServiceClient(authProvider, httpClient);
GroupCollectionResponse res = graphClient.groups().get();
Expected behavior
Alternative 1 should work
Screenshots
n.a.
Setup (please complete the following information):
-
OS: ubuntu
-
IDE: Intellij
// Include the sdk as a dependency
implementation 'com.microsoft.graph:microsoft-graph:6.+'
implementation 'com.azure:azure-identity:1.+'implementation 'org.springframework.boot:spring-boot-starter-web:3.4.4'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat:3.4.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test:3.4.4' -
Java version: 21
-
App Server/Environment: Spring boot local execution
-
Frameworks: Spring boot
Additional context
n.a.
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [/] Bug Description Added
- [/] Repro Steps Added
- [/] Setup information Added
Expected behavior
Alternative 1 should work
How to reproduce
See code snippet
SDK Version
microsoft-graph:6:34:0 microsoft-graph-core:3:6:1
Latest version known to work for scenario above?
No response
Known Workarounds
See code alternative 2
Debug output
Click to expand log
```Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getGraphClient' defined in class path resource [xxxxxxxxxxxxxxxxx.class]: Failed to instantiate [com.microsoft.graph.serviceclient.GraphServiceClient]: Factory method 'getGraphClient' threw exception with message: Access token is empty.
</details>
### Configuration
Ubuntu 22.04
x86
### Other information
_No response_
- Ngôn ngữ chính
- Java
- Star
- 444
- Fork
- 154
- Merge trung bình
- 18 giờ 28 phút
- Pull request đã merge (30 ngày)
- 4
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoftgraph/msgraph-sdk-java
-
status:waiting-for-triage type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
microsoftgraph/msgraph-sdk-java#2610 ·
-
status:waiting-for-triage type:bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
microsoftgraph/msgraph-sdk-java#2656 ·
-
status:waiting-for-triage type:bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
microsoftgraph/msgraph-sdk-java#2654 ·
-
status:waiting-for-triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
microsoftgraph/msgraph-sdk-java#2639 ·
-
Error in PATCH onlineMeeting Đang mởstatus:waiting-for-triage type:bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
microsoftgraph/msgraph-sdk-java#2589 · 1 bình luận ·
Tất cả issue của microsoftgraph/msgraph-sdk-java
Issue tương tự
-
bug untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
opensearch-project/ml-commons#5094 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
-
emitter:client:csharp feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
affects/8.10 affects/8.9 component/clients kind/bug likelihood/mid severity/mid
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 Đang mởbug frontend maui-pilot
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100