Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

323
Views
OAuth 1.0 Authentication for NetSuite

In vain I have tried to get OAuth 1.0 authentication working for Oracle Netsuite. When I generate the authentication header with PostMan it works, but my code, generates the wrong signature, despite the fact that I followed all the steps I could find on how to generate a HMAC-SHA1 signature for OAuth 1.0

Source code (Kotlin)

class NetsuiteAuthenticationScheme {

    private val algorithm = "HmacSHA1"
    private val charset = Charsets.UTF_8

    fun setAuthenticationHeaders(headers: HttpHeaders, url: String?) {

        val authentication = mutableMapOf(
                "realm" to "REALM",
                "oauth_consumer_key" to "CONSUMER_KEY",
                "oauth_token" to "TOKEN",
                "oauth_signature_method" to "HMAC-SHA1",
                "oauth_version" to "1.0",
                "oauth_timestamp" to "TIMESTAMP",
                "oauth_nonce" to "NONCE"
        )

        val signatureUrl = listOf(
                "POST",
                URLEncoder.encode(url, charset.displayName()),
                URLEncoder.encode(
                        URLEncodedUtils.format(
                                authentication
                                        .toList()
                                        .sortedBy { it.first }
                                        .map { BasicNameValuePair(it.first, it.second) },
                                charset.displayName()
                        ), charset.displayName()
                )
        ).joinToString("&")

        val signatureKey = listOf(
                "CONSUMER_SECRET",
                "TOKEN_SECRET"
        ).joinToString("&")

        authentication["oauth_signature"] = computeSignature(signatureUrl, signatureKey)

        val authenticationHeaderValue = authentication
                .toList()
                .joinToString { "${it.first}=\"${URLEncoder.encode(it.second, charset.displayName())}\"" }

        headers.contentType = MediaType.APPLICATION_JSON
        headers.add("Authorization", "OAuth $authenticationHeaderValue")
    }

    private fun computeSignature(data: String, key: String): String {
        val mac = Mac.getInstance(algorithm)
        mac.init(SecretKeySpec(key.toByteArray(charset), algorithm))
        return Base64.encodeBytes(mac.doFinal(data.toByteArray(charset)))
    }
}

What did I do wrong?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

There's an example of a working oAuth connection in Node at Netsuite OAuth Not Working

This line:

headers.Authorization += ',realm="' + config.accountId + '"';

appears to be what you are missing.

realm should not be part of the hash sent to compute signature.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!