private static void InitializeServiceClient(EwsRestGateway client) { if (client._token != null) { client.Credentials = new TokenCredentials(client._token?.access_token, client._token?.token_type); client.Credentials.InitializeServiceClient(client); } else { client.Credentials = null; } }
/// <summary> /// Creates a connection to an EwsRestGateway client. /// </summary> /// <param name="baseUri">URI where the client is located.</param> /// <param name="userName">UserName to authenticate with.</param> /// <param name="password">Password to authenticate with.</param> /// <param name="tokenEndpoint">Path where the bearer token can be retrieved.</param> public static EwsRestGateway Connect(Uri baseUri, string userName, string password, string tokenEndpoint = "GetToken") { var client = new EwsRestGateway { _token = BearerToken.ObtainToken(baseUri, userName, password, tokenEndpoint) }; client._password.LoadValue(password); client._userName.LoadValue(userName); InitializeServiceClient(client); return(client); }