Skip to content

Commit

Permalink
Authorize for custom provider
Browse files Browse the repository at this point in the history
  • Loading branch information
piotras committed Nov 3, 2014
1 parent fd8840b commit 1afd787
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions components/RemoteLogin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ noflo = require 'noflo'

getUrl = (params) ->
redirect = params.redirect or window.location.href
"#{params.site}$NOFLO_OAUTH_ENDPOINT_AUTHORIZE/#{params.provider}?client_id=#{params.clientid}&scope=#{params.scope}&response_type=code&redirect_uri=#{encodeURIComponent(redirect)}"
"#{params.site}$NOFLO_OAUTH_ENDPOINT_AUTHORIZE?client_id=#{params.clientid}&scope=#{params.scope}&response_type=code&redirect_uri=#{encodeURIComponent(redirect)}"

checkToken = (url, params, callback) ->
code = url.match /\?code=(.*)/
Expand All @@ -22,9 +22,15 @@ checkToken = (url, params, callback) ->
callback null, data.token
# get token directly from provider
if '$NOFLO_OAUTH_CLIENT_SECRET' isnt ''
redirect = params.redirect or window.location.href
redirect = params.redirect or window.location.href
post_params = "code=#{code[1]}&client_id=#{params.clientid}&grant_type=authorization_code&client_secret=$NOFLO_OAUTH_CLIENT_SECRET&redirect_uri=#{encodeURIComponent(redirect)}"
req.open 'POST', "#{params.site}$NOFLO_OAUTH_ENDPOINT_TOKEN", true
req.send 'code=#{code[1]}&client_id=#{params.clientid}&grant_type=authorization_code&client_secret=$NOFLO_OAUTH_CLIENT_SECRET&redirect_uri=#{encodeURIComponent(redirect)}'
# Set headers required for POST request
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.setRequestHeader "Content-length", post_params.length
req.setRequestHeader "Connection", "close"
# Send data
req.send post_params
# get token from oauth2 gate
if '$NOFLO_OAUTH_CLIENT_SECRET' is '' or null
req.open 'GET', "#{params.gatekeeper}$NOFLO_OAUTH_ENDPOINT_AUTHENTICATE/#{code[1]}", true
Expand Down

0 comments on commit 1afd787

Please sign in to comment.