public OAuth2AccessToken Authenticate(string username, string password) { // Obtains a new OAuth2 Access Token using the Resource Owner Password workflow // see https://www.jetbrains.com/hub/help/1.0/Resource-Owner-Password-Credentials.html var request = new RestRequest(OAuth2TokenResource, Method.POST); request.AddParameter("username", username); request.AddParameter("password", password); request.AddParameter("grant_type", "password"); request.AddParameter("scope", _youtrackScopeId); var client = GetClient(skipAuthentication: true); client.Authenticator = new HttpBasicAuthenticator(_clientId, _clientSecret); var response = client.Execute <OAuth2AccessToken>(request); DateTime dateObtained = DateTime.Now; try { EnsureExpectedResponseStatus(response, HttpStatusCode.OK); } catch (ConnectionException ex) { throw new AuthenticationException(Language.YouTrackClient_Login_Authentication_Failed, ex); } _resourceOwnerToken = response.Data; _resourceOwnerToken.DateObtained = dateObtained; return(_resourceOwnerToken); }
public void Authenticate(OAuth2AccessToken accessToken) { if (accessToken == null) { throw new ArgumentNullException("accessToken`"); } if (accessToken.IsExpired) { throw new ArgumentException("Access Token is Expired", "accessToken"); } _resourceOwnerToken = accessToken; }
public void Logout() { _resourceOwnerToken = null; }