public OperationResult RefreshAccessToken(string refreshToken, string clientID, string clientSecret) { //Check first if the registered application with specified clientid and clientsecret exists IFindRegisteredApplicationRepositoryExt registeredAppRepo = (IFindRegisteredApplicationRepositoryExt)RepositoryFactory.Create("Find.Tools.OAuthServerManager.RegisteredApplication"); List <RegisteredApplication> list = registeredAppRepo.FindByClientIDAndClientSecret(clientID, clientSecret); //If exists if (list != null && list.Count > 0) { //Check if the application has been authorized before by checking the access token previous existence IFindAccessTokenRepository accessTokenRepo = (IFindAccessTokenRepository)RepositoryFactory.Create("Find.Tools.OAuthServerManager.AccessToken"); List <AccessToken> accessTokenList = accessTokenRepo.FindByClientID(clientID); if (accessTokenList.Count == 0) { return(new OperationResult(false, null, "Access token for client ID " + clientID + " does not exists. The application had never asked for authorization!")); } else { AccessToken newAccessToken = (AccessToken)CreateNewAccessToken(refreshToken, clientID, clientSecret).Data; OperationResult result = SaveNewccessToken(newAccessToken); if (result.Result) { return(new OperationResult(true, newAccessToken, "New access token is created successfully!")); } else { return(result); } } } else { return(new OperationResult(false, null, "Application for client ID " + clientID + " does not exists. Application is not registered!")); } }
/// <summary> /// Finds all Access Token data with client I D containing specified keyword /// </summary> /// <param name="clientID"> Client I D</param> /// <returns>The result of the operation</returns> public OperationResult FindByClientID(string clientID) { IFindAccessTokenRepository repository = (IFindAccessTokenRepository)RepositoryFactory.Create(Keywords.FindAccessToken); try { List <AccessToken> res = repository.FindByClientID(clientID); return(new OperationResult(true, res)); } catch (Exception e) { return(new OperationResult(false, e)); } }