private async Task SaveTokenRecord(Dictionary <string, string> attributes, string token, AuthorizationEndpoint endpoint, SystemLoginEndpoint loginEndpoint) { if (!endpoint.KeepThirdPartyToken) { return; } var userKey = await GetUserKey(attributes, endpoint, loginEndpoint); var service = await GetService(endpoint); var record = await _thirdPartySystemTokenRecordStore.QueryByUserKey(userKey, loginEndpoint.ID, endpoint.ID); bool needUpdate = false; if (record == null) { record = new ThirdPartySystemTokenRecord() { ID = Guid.NewGuid(), AuthorizationEndpointID = endpoint.ID, SystemLoginEndpointID = loginEndpoint.ID, LastRefeshTime = DateTime.UtcNow, Timeout = await service.GetTimeout(endpoint.ThirdPartyConfiguration), Token = token, UserKey = userKey }; try { await _thirdPartySystemTokenRecordStore.Add(record); } catch (UtilityException ex) { if (ex.Code == (int)Errors.ExistSameThirdPartySystemTokenRecord) { record = await _thirdPartySystemTokenRecordStore.QueryByUserKey(userKey, loginEndpoint.ID, endpoint.ID); needUpdate = true; } else { throw ex; } } } else { needUpdate = true; } if (needUpdate) { record.Timeout = await service.GetTimeout(endpoint.ThirdPartyConfiguration); record.LastRefeshTime = DateTime.UtcNow; record.Token = token; await _thirdPartySystemTokenRecordStore.Update(record); } }
public async Task Update(ThirdPartySystemTokenRecord record) { await _thirdPartySystemTokenRecordStore.Update(record); }
public async Task Delete(ThirdPartySystemTokenRecord record) { await _thirdPartySystemTokenRecordStore.Delete(record.UserKey, record.ID); }
public async Task Refresh(ThirdPartySystemTokenRecord record) { var newToken = await record.AuthorizationEndpoint.RefreshToken(record.SystemLoginEndpoint, record.UserKey, record.Token); }
public async Task Add(ThirdPartySystemTokenRecord record) { await _thirdPartySystemTokenRecordStore.Add(record); }