/// <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); }
/// <summary> /// Obtains a new Bearer Token. Can only be called after a valid Connect call /// </summary> public void ReAuthenticate() { if (_token == null) { throw new InvalidOperationException("Cannot re-authenticate when authentication has never succeeded."); } _token = BearerToken.ObtainToken(_token.TokenUri, _userName.ExtractValue(), _password.ExtractValue(), string.Empty); InitializeServiceClient(this); if (_token != null) { Credentials = new TokenCredentials(_token?.access_token, _token?.token_type); } Credentials?.InitializeServiceClient(this); }