Getting Type mismatch: 'b64_hmac_sha1' error on Classic ASP OAuth 2.0 call for access token - oauth-2.0

I'm trying to get an OAuth 2.0 access_token and am getting an error message on the include page. here's the function that is giving the message.
Private Function Get_Signature()
Dim strBaseSignature : strBaseSignature = _
m_strMethod & "&" & _
Utils.URLEncode(m_strEndPoint) & "&" & _
Utils.URLEncode(m_strParameters)
Dim strSecret : strSecret = _
m_strConsumerSecret & "&" & _
m_strTokenSecret
Get_Signature = b64_hmac_sha1(strSecret, strBaseSignature)
End Function
End Class
The check page that is calling this function is as follows:
cso = LCase(Request.Form("user"))
pwd = LCase(Request.Form("password"))
appID = 82
Response.Cookies("username") = cso
Response.Cookies("password") = pwd
Response.Cookies("ValidUser") = Validated
Dim objOAuth : Set objOAuth = New cLibOAuth
objOAuth.ConsumerKey = "{client_id}"
objOAuth.ConsumerSecret = "{secretkey}"
objOAuth.EndPoint = "https://login.company.com/as/token.oauth2"
objOAuth.RequestMethod = OAUTH_REQUEST_METHOD_POST
objOAuth.TimeoutURL = "authenticate.asp"
objOAuth.Parameters.Add "username", Request.Cookies("username")
objOAuth.Parameters.Add "password", Request.Cookies("password")
objOAuth.Parameters.Add "oauth_callback", "callback.asp"
objOAuth.Send()
Dim strResponse : strResponse = _
objOAuth.Get_ResponseValue(access_token)
I'm getting an error message of Type mismatch: 'b64_hmac_sha1' in this section:
Get_Signature = b64_hmac_sha1(strSecret, strBaseSignature)
It should have ran the objOAuth call and added the request paramaters and went to the callback.asp page but it's failing on the paramaters.
I'm new to Oauth and rusty on classic asp. It's a project I have got to get finished so any help is appreciated.

Related

Upload Offline Conversion migration to V9

I used to upload offline conversion using following code in v201809 version as provided at
https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201809/Remarketing/UploadOfflineConversions.php
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->withClientCustomerId($customerid)->enablePartialFailure()->build();
$adWordsServices = new AdWordsServices();
$offlineConversionService = $adWordsServices->get($session, OfflineConversionFeedService::class);
$conversionName="OfflineConv";
$feed = new OfflineConversionFeed();
$feed->setConversionName($conversionName);
$feed->setConversionTime($conversionTime);
$feed->setConversionValue($conversionValue);
$feed->setGoogleClickId($gclid);
$offlineConversionOperation = new OfflineConversionFeedOperation();
$offlineConversionOperation->setOperator(Operator::ADD);
$offlineConversionOperation->setOperand($feed);
$offlineConversionOperations = [$offlineConversionOperation];
$result = $offlineConversionService->mutate($offlineConversionOperations);
Now I am upgrading to V9, I have used the code as provided at
https://github.com/googleads/google-ads-php/blob/main/examples/Remarketing/UploadOfflineConversion.php
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build();
//$conversionName="OfflineConv";
$conversionName = ConversionActionType::WEBPAGE;
$clickConversion = new ClickConversion([
'conversion_action' => ResourceNames::forConversionAction($customerId, $conversionName),
'gclid' => $gclid,
'conversion_value' => $conversionValue,
'conversion_date_time' => $conversionTime,
'currency_code' => 'USD'
]);
$conversionUploadServiceClient = $googleAdsClient->getConversionUploadServiceClient();
$result = $conversionUploadServiceClient->uploadClickConversions($customerid, [$clickConversion], true);
The problem is when we set $conversionName="OfflineConv"; we get following error.
Resource name 'customers/9025381111/conversionActions/OfflineConv' is malformed: expected 'customers/{customer_id}/conversionActions/{ConversionType.conversion_type_id}'., at conversions[0].conversion_action
and when we set $conversionName = ConversionActionType::WEBPAGE; we get following error.
This customer does not have an import conversion action that matches the conversion action provided., at conversions[0].conversion_action
Can someone help me?
Conversion Name must match the conversion action that you've already set up in your account. You're passing the enum value for the type.
It should be something like $conversionName = "OfflineConversions"
where "OfflineConversions" is exactly the name of the conversion in the conversions section of the web UI.
ConversionName has been removed from V9, use $conversionActionId as in example on github.
You need to try use parameter ctId from url your "OfflineConversions" in Google Ads UI as $conversionActionId.
Or try the solution from here.
For your example, replace this
$conversionName = ConversionActionType::WEBPAGE;
on this
$conversionName = {ctId from url};
You need to first create a click conversion
click_conversion = adwords_client.get_type("ClickConversion")
conversion_action_service = adwords_client.get_service('ConversionActionService')
click_conversion.conversion_action = (
conversion_action_service.conversion_action_path(
customer_id, conversion_action_id
)
)
The conversion_action_id is equivalent to conversion_name of previous version.
You can find the id using following snippet
ads: GoogleAdsServiceClient = self.adwords_client.get_service('GoogleAdsService')
pages = ads.search(query="SELECT conversion_action.id, conversion_action.name FROM conversion_action where conversion_action.name={conversion_name}", customer_id={customer_id})
for page in pages:
print(page.conversion_action)
Then you upload the conversion
click_conversion.gclid = gclid
click_conversion.conversion_value = conversion_value
click_conversion.conversion_date_time = conversion_time
click_conversion.currency_code = currency_code
conversion_upload_service = self.adwords_client.get_service("ConversionUploadService")
request = self.adwords_client.get_type("UploadClickConversionsRequest")
request.customer_id = customer_id
request.conversions.append(click_conversion)
request.partial_failure = True
conversion_upload_response = (
conversion_upload_service.upload_click_conversions(
request=request,
)
)
uploaded_click_conversion = conversion_upload_response.results[0]
print(
f"Uploaded conversion that occurred at "
f'"{uploaded_click_conversion.conversion_date_time}" from '
f'Google Click ID "{uploaded_click_conversion.gclid}" '
f'to "{uploaded_click_conversion.conversion_action}"'
)

how to pass additional parametes to spider parse function in scrapy during web scraping

I am trying to pass additional information to the parse function but it is giving a type error.
TypeError: parse() got an unexpected keyword argument 'body'
i am unable to resolve this issue.
"""
return [scrapy.Request(url=website.search_url.format(prod), callback=self.parse,
cb_kwargs = {"body":website.body_xpath,"product_list":website.products_list_xpath,
"names":website.products_name_xpath,"selling_price":website.selling_price_xpath,
"market_price":website.market_price_xpath}) for website in websites for prod in modified_products]
def parse(self, response):
body = response.cb_kwargs.get("body")
product_list = response.cb_kwargs.get("product_list")
name = response.cb_kwargs.get("names")
selling_price = response.cb_kwargs.get("selling_price")
market_price = response.cb_kwargs.get("market_price")
"""
I forgot to write those names in parse function definition, after adding them i am getting the correct result. Thanks for having a look at it.
"""
return [scrapy.Request(url=website.search_url.format(prod), callback=self.parse,
cb_kwargs = dict(body = website.body_xpath, product_list = website.products_list_xpath,
name = website.products_name_xpath, selling_price = website.selling_price_xpath,
market_price = website.market_price_xpath)) for website in websites for prod in modified_products]
def parse(self, response, body, product_list, name, selling_price, market_price):
body = response.cb_kwargs["body"]
product_list = response.cb_kwargs["product_list"]
name_ = response.cb_kwargs["name"]
selling_price_ = response.cb_kwargs["selling_price"]
market_price_ = response.cb_kwargs["market_price"]
"""

Google Closure Compile REST Api suddenly Throws Error 405 "Method not allowed"

I've been using Closure as part of y application to compress Javascript for a while now, but just started getting an error 405 - Method not allowed
My code as below was working for a couple of years, but has now stopped.
NOTE: this is not called frequently, just when ever any changes are detected in the Javascript files in my application.
I get no further error information from the Closure app than this.
Obviously this code performs a POST operation. If I use the form found here https://closure-compiler.appspot.com/home, it works, but if I either browser to the URL or use my code I get Error 405, it's almost as if my code is trying a GET method... but it's not...
Any ideas?
Public Class Closure
Property OriginalCode As String
Property CompiledCode As String
Property Errors As ArrayList
Property Warnings As ArrayList
Property Statistics As Dictionary(Of String, Object)
Public Sub New(Input As String, Optional CompliationLevel As String = "SIMPLE_OPTIMIZATIONS")
Dim _HttpWebRequest As HttpWebRequest
Dim _Result As StringBuilder
Dim ClosureWebServiceURL As String = "http://closure-compiler.appspot.com/compile?"
Dim ClosureWebServicePOSTData As String = "output_format=json&output_info=compiled_code" &
"&output_info=warnings" &
"&output_info=errors" &
"&output_info=statistics" &
"&compilation_level=" & CompliationLevel & "" &
"&warning_level=default" &
"&js_code={0}"
'// Create the POST data
Dim Data = String.Format(ClosureWebServicePOSTData, HttpUtility.UrlEncode(Input))
_Result = New StringBuilder
_HttpWebRequest = DirectCast(WebRequest.Create(ClosureWebServiceURL), HttpWebRequest)
_HttpWebRequest.Method = "POST"
_HttpWebRequest.ContentType = "application/x-www-form-urlencoded"
'//Set the content length to the length of the data. This might need to change if you're using characters that take more than 256 bytes
_HttpWebRequest.ContentLength = Data.Length
'//Write the request stream
Using SW As New StreamWriter(_HttpWebRequest.GetRequestStream())
SW.Write(Data)
End Using
Try
Dim response As WebResponse = _HttpWebRequest.GetResponse()
Using responseStream As Stream = response.GetResponseStream
Dim encoding As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Using readStream As New StreamReader(responseStream, encoding)
Dim read(256) As Char
Dim count As Integer = readStream.Read(read, 0, 256)
While count > 0
Dim str As New String(read, 0, count)
_Result.Append(str)
count = readStream.Read(read, 0, 256)
End While
End Using
End Using
Dim js As New JavaScriptSerializer
js.MaxJsonLength = Int32.MaxValue
Dim d As Dictionary(Of String, Object) = js.Deserialize(Of Dictionary(Of String, Object))(_Result.ToString())
Me.CompiledCode = d.NullKey("compiledCode")
Me.Warnings = TryCast(d.NullKey("warnings"), ArrayList)
Me.Errors = TryCast(d.NullKey("errors"), ArrayList)
Me.Statistics = TryCast(d.NullKey("statistics"), Dictionary(Of String, Object))
Catch ex As Exception
Me.CompiledCode = ""
If Me.Errors Is Nothing Then
Dim er As New List(Of String)
er.Add(ex.ToString())
Me.Errors = New ArrayList(er)
Else
Me.Errors.Add(ex.ToString())
End If
End Try
Me.OriginalCode = Input
End Sub
End Class
Closure REST api is redirecting to https, you may want to try to POST to "https://closure-compiler.appspot.com/compile" directly in order to avoid redirection.

CAPICOM and X509

I have a web application form. The aim is to create a xml of data from web form and sign it with the user usb certificate.
I am using CAPICOM.store to successfully open all user certificate. When I click on one that I want I exported it. After that I am importing selected certificate in X509Cetificate2 to sign xml. But in my code I am getting error on line
signedXml.ComputeSignature() and message is 'Signing key is not loaded.' Please any help or suggestion to fix this.
Function SignXML(uppXML As String) As String
Dim bResult As Boolean = False
Dim pCertContext As IntPtr = IntPtr.Zero
Dim doc As XmlDocument = Nothing
Dim signedXml As SignedXml = Nothing
Dim reference As Reference = Nothing
Dim trns As XmlDsigC14NTransform = Nothing
Dim env As XmlDsigEnvelopedSignatureTransform = Nothing
Dim keyInfo As KeyInfo = Nothing
Dim xmlDigitalSignature As XmlElement = Nothing
Dim hideFiledCapicom As String = Replace(txtCapicom.Text, " ", "+")
Dim certificate As New X509Certificate2(Convert.FromBase64String(hideFiledCapicom))
Dim key As AsymmetricAlgorithm = certificate.PrivateKey
doc = New XmlDocument
doc.PreserveWhitespace = True
doc.LoadXml(uppXML)
signedXml = New SignedXml(doc)
signedXml.SigningKey = key
reference = New Reference
reference.Uri = ""
trns = New XmlDsigC14NTransform
reference.AddTransform(trns)
env = New XmlDsigEnvelopedSignatureTransform
reference.AddTransform(env)
signedXml.AddReference(reference)
keyInfo = New KeyInfo()
keyInfo.AddClause(New KeyInfoX509Data(certificate))
signedXml.KeyInfo = keyInfo
signedXml.ComputeSignature()
xmlDigitalSignature = signedXml.GetXml()
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, True))
If TypeOf doc.FirstChild Is XmlDeclaration Then
doc.RemoveChild(doc.FirstChild)
End If
uppXML = doc.OuterXml
Return uppXML
End Function
I found solution for this.
In JavaScript where I use CAPICOM to choose and export certificate I am also getting and the private key from certificate and putting it in hidden fields.
var privateKey = certificates.Item(1).PrivateKey.KeySpec
var exportKey = document.getElementById("<%=hideFieldKey.ClientID%>");
exportKey = privateKey
document.getElementById('HiddenKey').value = exportKey;
In my vb code I use CspParameters() to get private key and RSACryptoServiceProvider() to proceed further for signing xml document.

LSXLC ODBC Stored Procedure

I'm trying to connect to an Oracle RDB database using LSXLC (ODBC Connector).
But when it comes to stored procedures I'm having a hard time getting it to work.
The code below always results in "Error: Parameter name not supplied: fnl_date, Connector 'odbc2', Method -Call-". The error is triggered on "count = connection.Call(input, 1, result)"
Can anyone tell me what I'm doing wrong?
Public Function testLsxlcProc()
On Error GoTo handleError
Dim connection As LCConnection("odbc2")
connection.Server = "source"
connection.Userid = "userid"
connection.Password = "password"
connection.procedure = "proc_name"
connection.Connect
If connection.IsConnected Then
Dim input As New LCFieldList()
Dim result As New LCFieldList()
Dim break As LCField
Set break = input.Append("fnl_date", LCTYPE_TEXT)
break.Text = "2014-07-01"
Dim agrNo As LCField
Set agrNo = input.Append("fnl_agreement_no", LCTYPE_TEXT)
agrNo.Text = "123456"
Dim curr As LCField
Set curr = input.Append("fnl_currency_code", LCTYPE_TEXT)
curr.Text = "SEK"
Dim stock As LCField
Set stock = input.Append("fnl_stock_id", LCTYPE_TEXT)
stock.Text = "01"
connection.Fieldnames = "status, value"
Dim count As Integer
count = connection.Call(input, 1, result)
Call logger.debug("Count: " & count)
Else
Error 2000, "Unable to connect to database."
End If
handleExit:
connection.Disconnect
Exit Function
handleError:
On Error Resume Next
Call logger.error(Nothing)
Resume handleExit
End Function
Thanks in advance!
I had made a stupid mistake and had a mismatch between the name of the input parameter in Domino and the name of the input parameter in the stored procedure.
Make sure all names match up and there shouldn't be a problem.
Stored-Procedure "mylib.MyStoredProc" wird aufgerufen ...
LcSession.Status = 12325: LC-Error: errCallStoredProc 12325 (Error: Parameter name not supplied: P_S651_AC, Connector 'odbc2', Method -Call-)
Solution: changed "mylib" into "MYLIB" and all was well.
Check not only Parameter-Names, but also the Search-Path.

Resources