Dispose IDisposable object before method returns

This commit is contained in:
TocoToucan 2017-09-16 15:10:24 +03:00
parent 218a5f8097
commit 51a5e963bb
1 changed files with 20 additions and 17 deletions

View File

@ -27,14 +27,14 @@ internal OAuth(string clientId, string clientSecret, string endpoint)
internal bool AuthenticateWithLogin(string username, string password)
{
var req = new AccessTokenRequestPassword(username, password)
using (var req = new AccessTokenRequestPassword(username, password)
{
Url = $@"{endpoint}/oauth/token",
Method = HttpMethod.POST,
ClientId = clientId,
ClientSecret = clientSecret
};
})
{
try
{
req.BlockingPerform();
@ -47,23 +47,26 @@ internal bool AuthenticateWithLogin(string username, string password)
Token = req.ResponseObject;
return true;
}
}
internal bool AuthenticateWithRefresh(string refresh)
{
try
{
var req = new AccessTokenRequestRefresh(refresh)
using (var req = new AccessTokenRequestRefresh(refresh)
{
Url = $@"{endpoint}/oauth/token",
Method = HttpMethod.POST,
ClientId = clientId,
ClientSecret = clientSecret
};
})
{
req.BlockingPerform();
Token = req.ResponseObject;
return true;
}
}
catch
{
//todo: potentially only kill the refresh token on certain exception types.