1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3
4 package com.azure.identity;
5
6 import com.azure.core.http.ProxyOptions;
7
8 import java.util.function.Function;
9
10 /**
11 * Options to configure the IdentityClient.
12 */
13 public final class IdentityClientOptions {
14 private static final String DEFAULT_AUTHORITY_HOST = "https://login.microsoftonline.com/";
15 private static final int MAX_RETRY_DEFAULT_LIMIT = 3;
16
17 private String authorityHost;
18 private int maxRetry;
19 private Function<Integer, Integer> retryTimeout;
20 private ProxyOptions proxyOptions;
21
22 /**
23 * Creates an instance of IdentityClientOptions with default settings.
24 */
25 public IdentityClientOptions() {
26 authorityHost = DEFAULT_AUTHORITY_HOST;
27 maxRetry = MAX_RETRY_DEFAULT_LIMIT;
28 retryTimeout = i -> (int) Math.pow(2, i - 1);
29 }
30
31 /**
32 * @return the Azure Active Directory endpoint to acquire tokens.
33 */
34 public String authorityHost() {
35 return authorityHost;
36 }
37
38 /**
39 * Specifies the Azure Active Directory endpoint to acquire tokens.
40 * @param authorityHost the Azure Active Directory endpoint
41 * @return IdentityClientOptions
42 */
43 public IdentityClientOptions authorityHost(String authorityHost) {
44 this.authorityHost = authorityHost;
45 return this;
46 }
47
48 /**
49 * @return the max number of retries when an authentication request fails.
50 */
51 public int maxRetry() {
52 return maxRetry;
53 }
54
55 /**
56 * Specifies the max number of retries when an authentication request fails.
57 * @param maxRetry the number of retries
58 * @return IdentityClientOptions
59 */
60 public IdentityClientOptions maxRetry(int maxRetry) {
61 this.maxRetry = maxRetry;
62 return this;
63 }
64
65 /**
66 * @return a Function to calculate seconds of timeout on every retried request.
67 */
68 public Function<Integer, Integer> retryTimeout() {
69 return retryTimeout;
70 }
71
72 /**
73 * Specifies a Function to calculate seconds of timeout on every retried request.
74 * @param retryTimeout the Function that returns a timeout in seconds given the number of retry
75 * @return IdentityClientOptions
76 */
77 public IdentityClientOptions retryTimeout(Function<Integer, Integer> retryTimeout) {
78 this.retryTimeout = retryTimeout;
79 return this;
80 }
81
82 /**
83 * @return the options for proxy configuration.
84 */
85 public ProxyOptions proxyOptions() {
86 return proxyOptions;
87 }
88
89 /**
90 * Specifies he options for proxy configuration.
91 * @param proxyOptions the options for proxy configuration
92 * @return IdentityClientOptions
93 */
94 public IdentityClientOptions proxyOptions(ProxyOptions proxyOptions) {
95 this.proxyOptions = proxyOptions;
96 return this;
97 }
98 }