Exemplo n.º 1
0
        public override ServerAccessGrant Token()
        {
            base.ValidClient();
            ServerAccessGrant accessGrant = OAuthService.GetServerAccessGrantByRefreshToken(RefreshToken);

            if (accessGrant == null)
            {
                OAuthError(AccessTokenRequestErrorCode.InvalidRequest, "refresh token invalid", 400);
            }
            if (ClientId != accessGrant.ClientId)
            {
                OAuthError(AccessTokenRequestErrorCode.InvalidRequest, "client id is not match.", 400);
            }

            //如果授权刷新凭证不在有效
            if (!accessGrant.IsRefreshEffective())
            {
                OAuthService.DeleteServerAccessGrant(accessGrant);
                OAuthError(AccessTokenRequestErrorCode.InvalidRequest, "refresh token expire", 400);
            }

            var refreshedToken = new ServerAccessGrant(accessGrant.ClientId, accessGrant.UserId)
            {
                Scope     = accessGrant.Scope,
                GrantType = accessGrant.GrantType
            };

            OAuthService.CreateServerAccessGrant(refreshedToken);
            OAuthService.DeleteServerAccessGrant(accessGrant);
            return(refreshedToken);
        }
Exemplo n.º 2
0
        public override ServerAccessGrant Token()
        {
            ValidClient();

            var code = OAuthService.GetAuthorizationCode(Code);

            if (code == null)
            {
                OAuthError(AccessTokenRequestErrorCode.InvalidRequest, "code invalid");
            }

            if (!code.IsEffect())
            {
                OAuthService.DeleteAuthorizationCode(code);
                OAuthError(AccessTokenRequestErrorCode.InvalidRequest, "code expire");
            }

            if (code.AppId != ClientId)
            {
                OAuthError(AccessTokenRequestErrorCode.InvalidRequest, "client id is not match.", 400);
            }

            OAuthService.DeleteAuthorizationCode(code);

            return(OAuthService.CreateServerAccessGrant(ClientId, code.UserId));
        }
Exemplo n.º 3
0
        public override ServerAccessGrant Token()
        {
            ValidClient();

            var result = OAuthService.ValidatePassword(UserName, Password, PlatCode, Browser, IpAddress, ExtendField);

            if (result.Code != 0)
            {
                OAuthError(result.Code.ToString(), result.Message, result.Code);
            }
            return(OAuthService.CreateServerAccessGrant(ClientId, result.UserId));
        }
Exemplo n.º 4
0
        public override ServerAccessGrant Token()
        {
            ValidClient();

            var accessGrant = OAuthService.GetServerAccessGrant(AccessToken);

            if (accessGrant == null)
            {
                OAuthError(AccessTokenRequestErrorCode.InvalidRequest, "invalid access token.");
            }
            if (!accessGrant.IsEffective())
            {
                OAuthError(AccessTokenRequestErrorCode.InvalidRequest, "access token expired.");
            }

            if (UserId <= 0)
            {
                OAuthError(AccessTokenRequestErrorCode.InvalidRequest, "invalid userid");
            }

            return(OAuthService.CreateServerAccessGrant(accessGrant.ClientId, UserId));
        }
Exemplo n.º 5
0
 public override ServerAccessGrant Token()
 {
     ValidClient();
     return(OAuthService.CreateServerAccessGrant(ClientId));
 }