Exemple #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);
        }
Exemple #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));
        }
Exemple #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));
        }
        public override AuthorizationCode Authorize()
        {
            base.Authorize();

            var result = OAuthService.ValidateThirdToken(AccessToken, MappingType, PlatCode, Browser, IpAddress, ExtendField);

            if (result.Code != 0)
            {
                OAuthError(result.Code.ToString(), result.Message, 400);
            }

            return(OAuthService.CreateAuthorizationCode(ClientId, result.UserId));
        }
        public override AuthorizationCode Authorize()
        {
            base.Authorize();

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

            if (result.Code != 0)
            {
                OAuthError(result.Code.ToString(), result.Message, 400);
            }

            return(OAuthService.CreateAuthorizationCode(ClientId, result.UserId));
        }
Exemple #6
0
        protected void ValidClient()
        {
            var client = OAuthService.GetClientAuth(ClientId);

            if (client == null)
            {
                OAuthError(AccessTokenRequestErrorCode.InvoidClient, "client id invalid.");
            }
            if (client.Status != ClientAuthStatus.Enabled)
            {
                OAuthError(AccessTokenRequestErrorCode.UnauthorizedClient, "client unauthorized", 401);
            }
            if (ClientSecret != client.Secret)
            {
                OAuthError(AccessTokenRequestErrorCode.InvoidClient, "client secret invalid.");
            }
        }
        /// <summary>
        /// 授权验证
        /// </summary>
        /// <returns>授权码</returns>
        public virtual AuthorizationCode Authorize()
        {
            var client = OAuthService.GetClientAuth(ClientId);

            if (client == null)
            {
                OAuthError(AccessTokenRequestErrorCode.InvoidClient, "client id invalid.");
            }
            if (client.Status == ClientAuthStatus.Disabled)
            {
                OAuthError(AccessTokenRequestErrorCode.UnauthorizedClient, "client unauthorized", 401);
            }

            var redirectUri = new Uri(client.CallbackPath);

            if (!String.Equals(RedirectUri.AbsolutePath, redirectUri.AbsolutePath, StringComparison.InvariantCulture))
            {
                OAuthError(AccessTokenRequestErrorCode.RedirectUriMismatch, "redirect uri mismatch.");
            }
            return(null);
        }
Exemple #8
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));
        }
Exemple #9
0
 public override ServerAccessGrant Token()
 {
     ValidClient();
     return(OAuthService.CreateServerAccessGrant(ClientId));
 }
Exemple #10
0
 static OAuthAuthorization()
 {
     oauthService = Projects.Framework.DependencyResolver.Resolve <OAuthService>();
 }