private void AddAuthResponseData(IHttpRequest req, IHasMobileRequestHead mobileRequest, ValidateAndGetNewTokenResponse response) { mobileRequest.AddExtensionData(ServiceUtils.MobileAuthTokenExtensionKey, response.NewToken); mobileRequest.AddExtensionData(MobileRequestUtils.MobileAuthLoginTypeExtensionKey, response.LoginType); bool isNonMemberAuthLoginType = MobileRequestUtils.IsNonMemberAuthLoginType(response.LoginType); if (string.IsNullOrWhiteSpace(response.UserID)) { if (IsOnDemandMode) { return; } throw new MobileRequestFilterException("OperationName: " + req.OperationName + "'MobileAuthService' service returned null or white space UserID!"); } if (!isNonMemberAuthLoginType) { mobileRequest.AddExtensionData(ServiceUtils.MobileUserIdExtensionKey, response.UserID); mobileRequest.AddExtensionData(ServiceUtils.MobileIsMemberAuthExtensionKey, bool.TrueString); if (mobileRequest.head != null) { mobileRequest.head.auth = response.NewToken; } return; } if (!IsPayment) { if (!AllowNonMemberAuth) { if (IsOnDemandMode) { return; } throw new MobileRequestFilterException("OperationName: " + req.OperationName + ". Non-Member auth mode is unsupported!"); } if (string.IsNullOrWhiteSpace(response.LoginName)) { if (IsOnDemandMode) { return; } throw new MobileRequestFilterNonMemberAuthException("OperationName: " + req.OperationName + ". Non-Member auth returned null or white space [LoginName] by 'MobileAuthService' service!"); } } mobileRequest.AddExtensionData(ServiceUtils.MobileUserIdExtensionKey, response.UserID); mobileRequest.AddExtensionData(ServiceUtils.MobileUserPhoneExtensionKey, response.LoginName); mobileRequest.AddExtensionData(ServiceUtils.MobileIsNonMemberAuthExtensionKey, bool.TrueString); if (mobileRequest.head != null) { mobileRequest.head.auth = response.NewToken; } }
protected virtual void AuthenticateRequest(IHttpRequest req, IHasMobileRequestHead mobileRequest, string auth) { if (mobileRequest.HasExtensionData(ServiceUtils.MobileAuthTokenExtensionKey)) { throw new MobileRequestFilterException( "OperationName: " + req.OperationName + ". Request Head Extension fileds have had the authenticated auth. Request Head has bad data or MobileRequestFilter has been applied."); } ValidateAndGetNewTokenResponse response = null; try { response = _mobileAuthServiceClient.ValidateAndGetNewToken(new ValidateAndGetNewTokenRequest() { Token = auth }); } catch (CServiceException ex) { if (IsOnDemandMode) { return; } throw new MobileRequestFilterException("OperationName: " + req.OperationName + ". Error happened when doing Auth.", ex); } catch (Exception ex) { if (IsOnDemandMode) { return; } throw new Exception("OperationName: " + req.OperationName + ". Error happened when connecting to mobile auth service: " + ex.Message, ex); } if (IsOnDemandMode && response.ReturnCode != 0) { return; } switch (response.ReturnCode) { case 0: break; case 1001: throw new MobileRequestFilterException("OperationName: " + req.OperationName + ". No auth for authentication. Message: " + response.Message + ". \nReference document: " + AuthWiki); case 2001: throw new MobileRequestFilterException("OperationName: " + req.OperationName + ". " + ServiceUtils.InvalidTokenExceptionMessage + " Message: " + response.Message + ". \nReference document: " + AuthWiki); case 9000: throw new MobileRequestFilterException("OperationName: " + req.OperationName + ". Mobile Auth Service Internal Exception. Message: " + response.Message + ". \nReference document: " + AuthWiki); default: throw new MobileRequestFilterException("OperationName: " + req.OperationName + ". Unknown Auth Service Return Code: " + response.ReturnCode + ". Message: " + response.Message + ". \nReference document: " + AuthWiki); } if (string.IsNullOrWhiteSpace(response.NewToken)) { if (IsOnDemandMode) { return; } throw new MobileRequestFilterException("OperationName: " + req.OperationName + ". Empty new auth was returned by MobileAuthService."); } AddAuthResponseData(req, mobileRequest, response); }