private void DeleteTimeoutEntities()
 {
     this.GetCollection <OAuthCodeEntity>().DeleteMany(
         Builders <OAuthCodeEntity> .Filter
         .Lt(entity => entity.TimeoutTimestamp, ConvertTimespan.Get(DateTime.Now))
         );
 }
 internal OAuthCodeEntity Get(string code, string clientID)
 {
     return(this.GetCollection <OAuthCodeEntity>().FindOneAndDelete(
                Builders <OAuthCodeEntity> .Filter
                .And(
                    Builders <OAuthCodeEntity> .Filter
                    .Eq(entity => entity.Code, code),
                    Builders <OAuthCodeEntity> .Filter
                    .Eq(entity => entity.ClientID, clientID),
                    Builders <OAuthCodeEntity> .Filter
                    .Gt(entity => entity.TimeoutTimestamp, ConvertTimespan.Get(DateTime.Now))
                    )
                ));
 }
コード例 #3
0
        public Tuple <OAuthErrorType, string> GetCode(string clientID, ICollection <string> scopes)
        {
            if (VerifyScopes(scopes) == OAuthErrorType.InvalidScope)
            {
                return(Tuple.Create(OAuthErrorType.InvalidScope, String.Empty));
            }

            OAuthCodeEntity entity = new OAuthCodeEntity()
            {
                Code             = RandomGenerator.GeneratorRandomNQCode(32),
                ClientID         = clientID,
                TimeoutTimestamp = ConvertTimespan.Get(DateTime.Now.AddMinutes(10)),
                Scopes           = scopes
            };

            AccessCodeDataProvider.Instance.Insert(entity);
            return(Tuple.Create(OAuthErrorType.NoError, entity.Code));
        }
コード例 #4
0
        public Tuple <OAuthErrorType, OAuthTokenEntity> GetToken(string clientID, string code)
        {
            OAuthCodeEntity codeEntity = AccessCodeDataProvider.Instance.Get(code, clientID);

            if (codeEntity == null)
            {
                return(Tuple.Create(OAuthErrorType.UnAuthorizedClient, new OAuthTokenEntity()));
            }
            ClientEntity     clientEntity = ClientInformationDataProvider.Instance.GetClientMetadata(clientID);
            OAuthTokenEntity accessToken  = new OAuthTokenEntity()
            {
                AccessToken  = RandomGenerator.GeneratorRandomNQCode(32),
                TokenType    = "authorization_code",
                ExpiresIn    = clientEntity.ExpiresIn,
                RefreshToken = RandomGenerator.GeneratorRandomNQCode(32),
                Scopes       = codeEntity.Scopes,
                StartTime    = ConvertTimespan.Get(DateTime.Now)
            };

            TokenDataProvider.Instance.Insert(accessToken);

            return(Tuple.Create(OAuthErrorType.NoError, accessToken));
        }