I'm a little confused with auth for a restlet , I ...
# suitescript
s
I'm a little confused with auth for a restlet , I have an external app that mainly uses NetSuite soap suite talk so I want to use the same auth creds so for a GET request what does the authorization header look like?
Copy code
consumer_key     ENV['NETSUITE_CONSUMER_KEY']
  consumer_secret  ENV['NETSUITE_CONSUMER_SECRET']
  token_id         ENV['NETSUITE_TOKEN_ID']
  token_secret     ENV['NETSUITE_TOKEN_SECRET']
s
this will show you what the header looks like https://netsuite.custhelp.com/app/answers/detail/a_id/77577#subsect_1520632392 the parameters there, you can use this to try and see if you can replicate it - for the params given, this is kind of a model answer you can use to test https://netsuite.custhelp.com/app/answers/detail/a_id/101883
s
I don't need to use the TBA workflow as I have a ENV['NETSUITE_TOKEN_ID'] ?
s
@Sim Greenbaum the parameters that you've listed will indicate you're probably using oauth, and probably oauth1.0. In these cases I'd make sure the signature provided is correct. in here a big thing will be that the parameters given is actually part of the signature generation
i could be not hitting the point tho ha
s
so I just need to create an oauth_signature= based on the 2nd article
s
I think you should if you can validate all the points in the article using those parameters but inevitably the biggest part, yes I'd validate the signature
@Sim Greenbaum do you use postman?
postman has this thing that can give you header info too
s
yeah i use insomnia same thing
🙌 1
what should i use for Nonce
im getting a 403 is there any way to figure out why it's invaild ? @Sciuridae54696d
b
the usual answer is that postman (and insomnia) both support oauth 1 as an authentication option
you should be looking to fill in your 4 tokens, the realm, and the signature method
hover over question mark icons to read help to learn what the optional fields do
s
question marks in insimonia ?
b
both insomnia and postman implement help for their fields in the same way
s
i see
my question is the NetSuite documents contradict each other , assuming i already have the 4 keys listed above what else do i need
Copy code
Authorization: OAuth realm="123456", oauth_consumer_key="ef40afdd8abaac111b13825dd5e5e2ddddb44f86d5a0dd6dcf38c20aae6b67e4", oauth_token="2b0ce516420110bcbd36b69e99196d1b7f6de3c6234c5afb799b73d87569f5cc", oauth_nonce="fjaLirsIcCGVZWzBX0pg", oauth_timestamp="1508242306", oauth_signature_method="HMAC-SHA256", oauth_version="1.0", oauth_signature="7mpNx1RdQn4VLSyeEwCK7jFBjGQ0blzwDSMU9Kg5Rmg%3D"
and then this header
b
the header is calculated for every request
you cant hardcode a header
use the built in authentication methods for insomnia
s
so i got it working inside insomnia but now i need to build inside my application which is rails/ruby
the key should be this
Copy code
key = "#{ENV["NETSUITE_CONSUMER_SECRET"]}&#{ENV["NETSUITE_TOKEN_SECRET"]}"
b
first attempt should be using something like https://github.com/oauth-xx/oauth-ruby
s
I'm using that is the key correct?
b
libraries will concatenate the 2 secrets for you
s
OAuth::Consumer.new("key", "secret", site: "https://agree2")
b
thats where you would input the consumer key and consumer secret
s
Ooh that was my mistake
@battk im still getting 401 when i use this library
b
what does the code look like
s
Copy code
consumer = OAuth::Consumer.new(ENV["NETSUITE_CONSUMER_KEY"], ENV["NETSUITE_CONSUMER_SECRET"], {
      site: "https://******.<http://restlets.api.netsuite.com|restlets.api.netsuite.com>",
      signature_method: "HMAC-SHA256",
      http_method: :get,
    })
    options = {realm: "****/", oauth_nonce: "qwertyuiopasdaaa",timestamp: Time.now.getutc.to_i.to_s }
    hash = { oauth_token: ENV["NETSUITE_TOKEN_ID"], oauth_token_secret: ENV["NETSUITE_TOKEN_SECRET"]}
    request_token =  OAuth::AccessToken.from_hash(consumer, hash)
Copy code
response = request_token.request(:get, "/app/site/hosting/restlet.nl?******",request_token,options )
b
what does the login audit trail tell you
s
doesnt even show up as a faliure
which means my code is failing but still returning 401
b
that means one of your parameters are missing
fair chance that your options are being defined in the wrong place
and incorrectly
you basically never want to define the nonce or timestamp yourself
and its likely that the realm is part of the Consumer's options
s
Good idea I will look tmmrw at the gem/library thanks @battk
yup thanks @battk