Permalink
Browse files

linked in api token access points needed secure https instead of http

there is one question TODO: is content length handled by req.write or
not?
  • Loading branch information...
1 parent ea31732 commit 362a16e6c911328ced25a1e2e9164ddb41f28ed4 @markomanninen markomanninen committed Dec 13, 2011
Showing with 76 additions and 12 deletions.
  1. +1 −0 examples/analytics.coffee
  2. +56 −0 examples/linkedin.coffee
  3. +6 −4 lib/scribe.js
  4. +3 −3 lib/widgets/LinkedInApi.js
  5. +7 −2 src/scribe.coffee
  6. +3 −3 src/widgets/LinkedInApi.coffee
@@ -143,6 +143,7 @@ plot_profiles = (robot, msg, account, webproperty = null) ->\
handle_authorization robot, msg
+# after getting authorization url and pin code, use it with next command:
handle_verification robot, msg, ''
get_profiles robot, msg
View
@@ -0,0 +1,56 @@
+scribe = require('/node_modules/scribe-node/scribe').load(['OAuth', 'LinkedInApi'])
+
+robot = {}
+robot['brain'] = {}
+robot['brain']['data'] = {}
+
+msg = {}
+msg['send'] = (msg) ->\
+ console.log msg
+
+_oauth = null
+_service = null
+_access_token = null
+
+services = {}
+
+services['linkedin'] = {'provider': scribe.LinkedInApi, 'key': '{api_key}', 'secret': '{api_secret}', 'scope': '', 'callback': 'oob'}
+
+get_oauth = (robot) ->\
+ if not _oauth\
+ _oauth = new scribe.OAuth robot.brain.data, 'linkedin', services\
+ return _oauth
+
+get_service = (robot) ->\
+ if not _service\
+ _service = get_oauth(robot).create_service()\
+ return _service
+
+get_access_token = (robot) ->\
+ if not _access_token\
+ _access_token = get_oauth(robot).get_access_token()\
+ return _access_token
+
+handle_authorization = (robot, msg) ->\
+ callback = (url) ->\
+ message = if url then url else "Error on retrieving url. See logs for more details."\
+ msg.send message\
+ get_oauth(robot).get_authorization_url(callback)
+
+handle_verification = (robot, msg, code) ->\
+ api = 'linkedin'\
+ callback = (response) ->\
+ if response\
+ if not robot.brain.data.oauth_user\
+ robot.brain.data.oauth_user = []\
+ robot.brain.data.oauth_user[api] = 'marko'\
+ message = "Verification done"\
+ else\
+ message = "Error on verification process. See logs for more details."\
+ msg.send message\
+ get_oauth(robot).set_verification_code(code, callback)
+
+handle_authorization robot, msg
+
+# after getting authorization url and pin code, use it with next command:
+handle_verification robot, msg, '{code}'
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -335,14 +335,19 @@ class Request
params = params_to_query @queryStringParams, encode_data
options['path'] = parsed_options['pathname'] + (if params then '?'+params else '')
options['method'] = @verb
+ post_data = null
+ if @verb == Verb.PUT || @verb == Verb.POST
+ post_data = params_to_query @bodyParams, encode_data
+ #some services might need content length header, but question is, if req.write handles it already?
+ #@headers['Content-Length'] = Buffer.byteLength(post_data, @encoding)
options['headers'] = @headers
#console.log 'OPTIONS: ' + JSON.stringify options
protocol = if parsed_options['protocol'] == 'https:' then https else http
req = @request protocol, options, callback
req.on 'error', (e) ->
console.log 'Problem with sent request: ' + e.message
- if @verb == Verb.PUT || @verb == Verb.POST
- req.write params_to_query @bodyParams, encode_data
+ if post_data
+ req.write post_data
req.end()
addHeader: (key, value) ->
@@ -7,9 +7,9 @@ api = require('../scribe').DefaultApi10a
# Register: https://www.linkedin.com/secure/developer
class root.LinkedInApi extends api
constructor: ->
- @REQUEST_TOKEN_URL = "http://api.linkedin.com/uas/oauth/requestToken"
- @ACCESS_TOKEN_URL = "http://api.linkedin.com/uas/oauth/accessToken"
- @AUTHORIZE_URL = "http://api.linkedin.com/uas/oauth/authorize?oauth_token="
+ @REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken"
+ @ACCESS_TOKEN_URL = "https://api.linkedin.com/uas/oauth/accessToken"
+ @AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authorize?oauth_token="
getAccessTokenEndpoint: ->
return @ACCESS_TOKEN_URL

0 comments on commit 362a16e

Please sign in to comment.