Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Storing access token to Dropbox.

  • Loading branch information...
commit d8d4aca855aae9e4b7e143b9abe34fc3dfec75c0 1 parent adcaa5f
@akoprow akoprow authored
Showing with 37 additions and 19 deletions.
  1. +27 −11 src/dropbox.opa
  2. +2 −1  src/facebook.opa
  3. +8 −7 src/webshell.opa
View
38 src/dropbox.opa
@@ -38,26 +38,42 @@ Please re-run your application with: --dropbox-config option")
private DropboxOAuth = Dropbox(config).OAuth
- private redirect = "http://localhost:8080"
-
- exposed function connect() {
- token = DropboxOAuth.get_request_token(redirect)
- match (token) {
- case {success: token}:
- auth_url = DropboxOAuth.build_authorize_url(token.token, redirect)
- Client.goto(auth_url)
- default:
- Log.error("Dropbox", "authorization failed")
+ private redirect = "http://{Config.host}/connect/dropbox"
+
+ private access_token = UserContext.make((option(string)) none)
+
+ exposed function get_access_token() {
+ function get_token(cache) {
+ match (cache) {
+ case {some: token}: some(token)
+ default:
+ token = DropboxOAuth.get_request_token(redirect)
+ match (token) {
+ case {success: token}:
+ auth_url = DropboxOAuth.build_authorize_url(token.token, redirect)
+ Client.goto(auth_url)
+ none
+ default:
+ Log.error("Dropbox", "authorization failed")
+ none
+ }
+ }
}
+ UserContext.execute(get_token, access_token)
}
xhtml =
WBootstrap.Button.make(
{ button:
<span>Dropbox</>
- , callback: function(_) { connect() }
+ , callback: function(_) { token = get_access_token(); void }
},
[]
)
+ function connect(token) {
+ Log.info("Dropbox", "Registering access token {token}")
+ UserContext.change(function (_) { some(token) }, access_token)
+ }
+
}
View
3  src/facebook.opa
@@ -72,13 +72,14 @@ Please re-run your application with: --fb-config option")
[]
)
- function Login.user login(token) {
+ function login(token) {
match (FBA.get_token_raw(token, redirect)) {
case {~token}:
fb_user = { ~token, name: get_fb_name(token) }
{~fb_user}
case {error:_}: {guest}
}
+ |> Login.set_current_user
}
function get_name(user) {
View
15 src/webshell.opa
@@ -110,14 +110,15 @@ function page() {
)
}
+function connect(connector, raw_data) {
+ connector(Text.to_string(raw_data))
+ Resource.default_redirection_page("/")
+}
+
dispatcher = parser
-| "/connect?" data=(.*) ->
- {
- FacebookConnect.login(Text.to_string(data)) |> Login.set_current_user
- Resource.default_redirection_page("/")
- }
-| .* ->
- page()
+| "/connect/facebook?" data=(.*) -> connect(FacebookConnect.login, data)
+| "/connect/dropbox?" data=(.*) -> connect(DropboxConnect.connect, data)
+| .* -> page()
Server.start(Server.http, { custom: dispatcher })
Please sign in to comment.
Something went wrong with that request. Please try again.