Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Twitter: finished authentication.

  • Loading branch information...
commit 5bb0149a65a8195b1aefd1a2f4c8807f5ce9323f 1 parent 4d66ed5
@akoprow akoprow authored
Showing with 37 additions and 12 deletions.
  1. +5 −5 src/dropbox.opa
  2. +31 −6 src/twitter.opa
  3. +1 −1  src/webshell.opa
View
10 src/dropbox.opa
@@ -9,9 +9,9 @@ database Dropbox.conf /dropbox_config
// TODO? could the generic OAuth authentication be bundled in that module?
// only providing a single simple function?
-type Dropbox.credentials = {no_credentials}
- or {string request_secret, string request_token}
- or {Dropbox.creds authenticated, string path}
+type Dropbox.status = {no_credentials}
+ or {string request_secret, string request_token}
+ or {Dropbox.creds authenticated, string path}
module DropboxConnect {
@@ -145,7 +145,7 @@ Please re-run your application with: --dropbox-config option")
}
function path_available(path) {
- true
+ true // FIXME
}
function ls(state) {
@@ -179,7 +179,7 @@ Please re-run your application with: --dropbox-config option")
}
Service.spec spec =
- { initial_state: Dropbox.credentials {no_credentials},
+ { initial_state: Dropbox.status {no_credentials},
metadata: {
id: "dropbox",
description: "Managing Dropbox file storage",
View
37 src/twitter.opa
@@ -6,9 +6,9 @@ import stdlib.apis.{twitter, oauth}
database Twitter.configuration /twitter_config
-type Twitter.credentials = {no_credentials}
- or {string request_secret, string request_token}
- or {Twitter.credentials authenticated}
+type Twitter.status = {no_credentials}
+ or {string request_secret, string request_token}
+ or {Twitter.credentials authenticated}
module TwitterConnect
{
@@ -49,8 +49,33 @@ Please re-run your application with: --twitter-config option")
private redirect = "http://{Config.host}/connect/twitter"
- function login(raw_token) {
- error("YYY")
+ function login(executor)(raw_token) {
+ function connect(auth_data) {
+ Log.info("Twitter", "connection data: {raw_token}")
+ authentication_failed = {no_credentials}
+ match (auth_data) {
+ case ~{request_secret, request_token}:
+ match (TWA.connection_result(raw_token)) {
+ case {success: s}:
+ if (s.token == request_token) {
+ match (TWA.get_access_token(s.token, request_secret, s.verifier)) {
+ case {success: s}:
+ twitter_creds = {access_token: s.token, access_secret: s.secret}
+ Log.info("Twitter", "got credentials: {twitter_creds}")
+ {authenticated: twitter_creds}
+ default:
+ authentication_failed
+ }
+ } else
+ authentication_failed
+ default:
+ authentication_failed
+ }
+ default:
+ authentication_failed
+ }
+ }
+ executor(connect)
}
private function authenticate() {
@@ -76,7 +101,7 @@ Please re-run your application with: --twitter-config option")
}
Service.spec spec =
- { initial_state: Twitter.credentials {no_credentials},
+ { initial_state: Twitter.status {no_credentials},
metadata: {
id: "twitter",
description: "Managing Twitter account",
View
2  src/webshell.opa
@@ -114,7 +114,7 @@ dispatcher = parser {
case "/connect/facebook?" data=(.*) ->
connect(FacebookConnect.login, data)
case "/connect/twitter?" data=(.*) ->
- connect(TwitterConnect.login, data)
+ connect(TwitterConnect.login(twitter.fun_executor), data)
case "/connect/dropbox?" data=(.*) ->
connect(DropboxConnect.login(dropbox.fun_executor), data)
case .* ->

0 comments on commit 5bb0149

Please sign in to comment.
Something went wrong with that request. Please try again.