Rest Example 2017R2 release

1
0
-1

Hi

I hope someone can help, I have been reading the example on new REST features with PB2017 R2 - the article states it is using a a service that doesnt use authentication.

How would i use a service that requires authentication

The one i am using needs for example ( where asdf1234 is the password )

X-Auth BEARER asdf1234

regards

 

Andrew

Question Tags: 

Answers

René Ullrich answered Rest Example 2017R2 release

1
+2
-1

The "Authorization" request header for basic authentication is a string that starts with "Basic ". Then follows a BASE64 codes string of "username:password".

For Base64 encoding you may use the CryptBinaryToStringW function of Windows API:

Function Boolean CryptBinaryToString ( &
    blob pbBinary, &
    ulong cbBinary, &
    ulong dwFlags, &
    Ref string pszString, &
    Ref ulong pcchString) Library "Crypt32.dll" Alias For "CryptBinaryToStringW"

 

blob lblob_text
string ls_b64
unsignedlong lul_buflen
CONSTANT ulong        CRYPT_STRING_BASE64     = 1
CONSTANT ulong        CRYPT_STRING_NOCRLF     = 1073741824


IF IsNull (as_text) THEN return as_text

lblob_text = Blob (as_text, EncodingUTF8!)
ls_b64 = Space (2 + 1.5 * (Len (lblob_text) + 2))
lul_buflen = Len (ls_b64)

IF Not CryptBinaryToString (lblob_text, Len (lblob_text), CRYPT_STRING_BASE64 + CRYPT_STRING_NOCRLF, ls_b64, lul_buflen) THEN
    // error handling
End If

return ls_b64

Chris Pollach's picture

Hi René et Al;

  FYI ... The next Appeon PB release PB2017R3 coming out next month - BASE64, Cryptography, etc methods will be built-in.   wink

Regards ... Chris

Simone Olianti answered Rest Example 2017R2 release

1
0
-1

Probably you should set a request header. Something like this:

ls_access = 'Bearer asdf1234'
ln_http.SetRequestHeader("Authorization", ls_access)

Andrew Davis's picture

Simone

Thanks for your reply - however that is not working - i still get 401 {"error":"Unauthorized"}

regards

Andrew