Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
 public async Task Update(ThirdPartySystemTokenRecord record)
 {
     await _thirdPartySystemTokenRecordStore.Update(record);
 }
Ejemplo n.º 3
0
 public async Task Delete(ThirdPartySystemTokenRecord record)
 {
     await _thirdPartySystemTokenRecordStore.Delete(record.UserKey, record.ID);
 }
Ejemplo n.º 4
0
 public async Task Refresh(ThirdPartySystemTokenRecord record)
 {
     var newToken = await record.AuthorizationEndpoint.RefreshToken(record.SystemLoginEndpoint, record.UserKey, record.Token);
 }
Ejemplo n.º 5
0
 public async Task Add(ThirdPartySystemTokenRecord record)
 {
     await _thirdPartySystemTokenRecordStore.Add(record);
 }