Having a lot of trouble performing oauth with a service


#1

There are a lot of oauth packages available, but unfortunately, I need one with Battle.net for my project. The api is listed in here.
https://dev.battle.net/docs/read/oauth

However, a problem I have been having is with the state parameter within the request. After configuration, I have been getting this error repeatedly on the server

W20150305-08:58:05.558(-5) (oauth_server.js:78) Unable to parse state from OAuth query: 
W20150305-08:58:05.558(-5) (oauth_server.js:78) Unable to parse state from OAuth query: 
W20150305-08:58:05.559(-5) (oauth_server.js:398) Error in OAuth Server: invalid_request

My url on the client looks as follows:

https://us.battle.net/oauth/authorize?response_type=code&client_id=rs39bq4r7wd5668nwgbewwbe4fvyjzju&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2F_oauth%2Fbattlenet%3Fclose&scope=wow.profile&state=eyJsb2dpblN0eWxlIjoicG9wdXAiLCJjcmVkZW50aWFsVG9rZW4iOiJPTVJuVmZWemk0QWJwVGJKYVN2UklTbWJ6MWExckF1VEJTdTNvYWtDU1ZOIn0=

I create the state as follows:

var credentialToken = Random.secret();
var loginStyle = OAuth._loginStyle('battlenet', config, options);
var state = OAuth._stateParam(loginStyle, credentialToken);

Anyone have any input? I was going off of this example but making my own package for bnet.

EDIT: Adding some details.
I tried using raw HTTP with python.

>>> login_url
'https://us.battle.net/oauth/authorize?response_type=code&client_id=rs39bq4r7wd5668nwgbewwbe4fvyjzju&redirect_uri=http://localhost:3000/_oauth/battlenet?close&scope=wow.profile&state=XE8CWJ57EK'
>>> response = requests.get(auth_url)
>>> pp(response.json())
{'inputs': [{'input_id': 'account_name',
             'label': 'E-mail',
             'max_length': 320,
             'type': 'text'},
            {'input_id': 'password',
             'label': 'Password',
             'max_length': 16,
             'type': 'password'},
            {'input_id': 'log_in_submit',
             'label': 'Log In',
             'type': 'submit'}],
 'type': 'LOGIN_FORM'}

#2

Are you encoding / decoding the URL? This looks a bit wrong “http%3A%2F%2Fl”

Maybe check out http://meyerweb.com/eric/tools/dencoder/ and http://www.w3schools.com/tags/ref_urlencode.asp