more register stuff

This commit is contained in:
Jeena Paradies 2012-10-25 07:56:40 +02:00
parent 365e6e034c
commit 8faf687bc5
18 changed files with 843 additions and 158 deletions

BIN
.DS_Store vendored

Binary file not shown.

View file

@ -75,7 +75,7 @@
- (void)initHotKeys {
NSInteger newTweetKey = kVK_ANSI_T; // http://boredzo.org/blog/archives/2007-05-22/virtual-key-codes
NSInteger newTweetKey = kVK_ANSI_M; // http://boredzo.org/blog/archives/2007-05-22/virtual-key-codes
NSInteger newTweetModifierKey = controlKey + cmdKey + optionKey; // cmdKey 256, shitfKey 512, optionKey 2048, controlKey 4096
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
@ -175,7 +175,7 @@
- (void)openNewMessageWindowWithString:(NSString *)aString {
[NSApp activateIgnoringOtherApps:YES];
NSRange range = [aString rangeOfString:@"oauth_token"];
NSRange range = [aString rangeOfString:@"oauthtoken"];
if (range.length > 0) {
[oauthView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"tentia_oauth.requestAccessToken('%@')", aString]];

View file

@ -6,8 +6,6 @@
// Licence: BSD (see attached LICENCE.txt file).
//
MY_ENTITY = "https://jeena.tent.is";
function getURL(url, type, callback, data) {
$.ajax({
url: url,
@ -22,12 +20,43 @@ function getURL(url, type, callback, data) {
alert(ajaxOptions);
alert(thrownError);
}
});
});
}
function OauthImplementation() {
this.requestProfileURL(MY_ENTITY);
//this.requestAToken();
function makeid(len) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < len; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function OauthImplementation(entity) {
this.entity = entity || "http://lala.home.jeena.net:3002";
this.app_info = {
"id": null,
"name": "Tentia",
"description": "A small TentStatus client.",
"url": "http://jabs.nu/Tentia/",
"icon": "http://jabs.nu/Tentia/icon.png",
"redirect_uris": [
"tentia://oauthtoken"
],
"scopes": {
"read_posts": "Uses posts to show them in a list",
"write_posts": "Posts on users behalf"
}
};
this.register_data = null;
this.profile = null;
this.state = null;
this.requestProfileURL(this.entity);
}
OauthImplementation.prototype.apiRoot = function() {
return this.profile["https://tent.io/types/info/core/v0.1.0"]["servers"][0];
}
OauthImplementation.prototype.requestProfileURL = function (entity) {
@ -35,44 +64,94 @@ OauthImplementation.prototype.requestProfileURL = function (entity) {
getURL(entity, "HEAD", function(resp) {
var headers = resp.getAllResponseHeaders();
var regex = /Link: <([^>]*)>; rel="https:\/\/tent.io\/rels\/profile"/;
var matches = headers.match(regex)
alert(matches[1]);
those.register(matches[1]);
var profile_url = headers.match(regex)[1]
if (profile_url == "/profile") {
profile_url = entity + "/profile";
}
those.register(profile_url);
});
}
OauthImplementation.prototype.register = function (url) {
var app_info = {
"name": "Tentia",
"description": "A small TentStatus client.",
"url": "http://jabs.nu/Tentia/",
"icon": "http://jabs.nu/Tentia/icon.png",
"redirect_uris": [
"tentia://oauth_token"
],
"scopes": {
"read_posts": "Uses posts to show them in a list",
"write_posts": "Posts on users behalf"
}
};
var those = this;
getURL(url, "GET", function(resp) {
var profile = JSON.parse(resp.responseText);
var server = profile["https://tent.io/types/info/core/v0.1.0"]["servers"][0];
this.profile = JSON.parse(resp.responseText);
var callback = function(resp) {
alert(JSON.parse(resp.responseText));
var data = JSON.parse(resp.responseText);
those.authRequest(data);
}
getURL(server + "/apps", "POST", callback, JSON.stringify(app_info));
getURL(those.apiRoot() + "/apps", "POST", callback, JSON.stringify(those.app_info));
});
}
OauthImplementation.prototype.authRequest = function(register_data) {
// id
// mac_key_id
// mac_key
// mac_algorithm
this.register_data = register_data;
this.state = makeid(19);
var auth = "/oauth/authorize?client_id=" + register_data["id"]
+ "&redirect_uri=" + escape(this.app_info["redirect_uris"][0])
+ "&scope=" + Object.keys(this.app_info["scopes"]).join(",")
+ "&state=" + this.state
+ "&tent_post_types=" + escape("https://tent.io/types/posts/status/v0.1.0");
controller.openURL_(those.apiRoot() + auth);
}
OauthImplementation.prototype.requestAccessToken = function(responseBody) {
// /oauthtoken?code=51d0115b04d1ed94001dde751c5b360f&state=aQfH1VEohYsQr86qqyv
var urlVars = getUrlVars(responseBody);
if(this.state && this.state != "" && urlVars["state"] == this.state) {
var code = urlVars["code"];
var url = this.apiRoot() + "/apps/" + this.register_data["id"] + "/authorizations";
} else {
alert("State is not the same: {" + this.state + "} vs {" + urlVars["state"] + "}")
}
this.state = null; // reset the state
/*
var urlVars = getUrlVars(responseBody);
var url = OAUTH_ACCESS_TOKEN_URL;
var _this = this;
var accessTokenKey = getUrlVars(responseBody)
var message = { method:"POST" , action:url };
OAuth.completeRequest(message,
{ consumerKey : OAUTH_CONSUMER_KEY
, consumerSecret: OAUTH_CONSUMER_SECRET
, token : urlVars["oauth_token"]
, tokenSecret : urlVars["oauth_verifier"]
});
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", OAuth.getAuthorizationHeader("", message.parameters));
},
url: url,
type: 'POST',
dataType: 'text',
success: function(data) {
_this.requestAccessTokenTicketFinished(data);
},
error:function (xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
alert(ajaxOptions);
alert(thrownError);
}
});*/
}
OauthImplementation.prototype.requestAToken = function() {
@ -111,41 +190,6 @@ OauthImplementation.prototype.requestTokenTicketFinished = function(data) {
controller.openURL_(OAUTH_USER_AUTHORIZATION_URL + "?" + data);
}
OauthImplementation.prototype.requestAccessToken = function(responseBody) {
// "twittia://oauth_token?oauth_token=jCcf7ClzJMbE4coZdONi467OAQxRGOBZJsuopG8C8&oauth_verifier=BK2ZkAIz51lqI4qta8MnKc280GyDLy0OQBpdsEmjT40"
var urlVars = getUrlVars(responseBody);
var url = OAUTH_ACCESS_TOKEN_URL;
var _this = this;
var accessTokenKey = getUrlVars(responseBody)
var message = { method:"POST" , action:url };
OAuth.completeRequest(message,
{ consumerKey : OAUTH_CONSUMER_KEY
, consumerSecret: OAUTH_CONSUMER_SECRET
, token : urlVars["oauth_token"]
, tokenSecret : urlVars["oauth_verifier"]
});
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", OAuth.getAuthorizationHeader("", message.parameters));
},
url: url,
type: 'POST',
dataType: 'text',
success: function(data) {
_this.requestAccessTokenTicketFinished(data);
},
error:function (xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
alert(ajaxOptions);
alert(thrownError);
}
});
}
OauthImplementation.prototype.requestAccessTokenTicketFinished = function(responseBody) {
var urlVars = getUrlVars(responseBody);

Binary file not shown.

View file

@ -11,9 +11,8 @@
1DDD582D0DA1D0D100B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD582A0DA1D0D100B32029 /* MainMenu.xib */; };
1F122D49118E1DE100E83B77 /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 1F122D48118E1DE100E83B77 /* Icon.icns */; };
1F1990C6117BCA960049BEA7 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F1990C5117BCA960049BEA7 /* ApplicationServices.framework */; };
1F245D6F1632AEFE00E4469A /* jso.js in Sources */ = {isa = PBXBuildFile; fileRef = 1F245D6E1632AEFE00E4469A /* jso.js */; };
1F2746FC12D9057600339B4F /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 1FE2FCA6117A8952000504B0 /* dsa_pub.pem */; };
1F3642EF118C8C35008198EF /* oauth.js in Resources */ = {isa = PBXBuildFile; fileRef = 1F3642ED118C8C35008198EF /* oauth.js */; };
1F3642F0118C8C35008198EF /* sha1.js in Resources */ = {isa = PBXBuildFile; fileRef = 1F3642EE118C8C35008198EF /* sha1.js */; };
1F4673FE1180F7EA006CC37C /* Core.js in Resources */ = {isa = PBXBuildFile; fileRef = 1F4673E61180F654006CC37C /* Core.js */; };
1F4674081180F7EE006CC37C /* jQuery.js in Resources */ = {isa = PBXBuildFile; fileRef = 1F4673E21180F519006CC37C /* jQuery.js */; };
1F4674091180F7F3006CC37C /* jQuery-Plugins.js in Resources */ = {isa = PBXBuildFile; fileRef = 1F4673E41180F590006CC37C /* jQuery-Plugins.js */; };
@ -67,8 +66,7 @@
1F1990C5117BCA960049BEA7 /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; };
1F1990DF117BD2250049BEA7 /* Appcast.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Appcast.xml; sourceTree = "<group>"; };
1F1990E1117BD2650049BEA7 /* ReleaseNotes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; lineEnding = 0; path = ReleaseNotes.html; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.html; };
1F3642ED118C8C35008198EF /* oauth.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = oauth.js; sourceTree = "<group>"; };
1F3642EE118C8C35008198EF /* sha1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = sha1.js; sourceTree = "<group>"; };
1F245D6E1632AEFE00E4469A /* jso.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = jso.js; sourceTree = "<group>"; };
1F36440E118CC173008198EF /* OAuthConsumer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = OAuthConsumer.framework; sourceTree = "<group>"; };
1F4673E21180F519006CC37C /* jQuery.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = jQuery.js; sourceTree = "<group>"; };
1F4673E41180F590006CC37C /* jQuery-Plugins.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "jQuery-Plugins.js"; sourceTree = "<group>"; };
@ -159,8 +157,7 @@
1FFA36C71177D861006C8562 /* WebKit */ = {
isa = PBXGroup;
children = (
1F3642ED118C8C35008198EF /* oauth.js */,
1F3642EE118C8C35008198EF /* sha1.js */,
1F245D6E1632AEFE00E4469A /* jso.js */,
1F4673E61180F654006CC37C /* Core.js */,
1FC254911427ADF90035D84B /* OauthImplementation.js */,
1FC2549D1427DC2B0035D84B /* Constants.js */,
@ -302,8 +299,6 @@
1FC2549F1427DC7F0035D84B /* Constants.js in Resources */,
1FC254951427BF150035D84B /* OauthImplementation.js in Resources */,
1F2746FC12D9057600339B4F /* dsa_pub.pem in Resources */,
1F3642EF118C8C35008198EF /* oauth.js in Resources */,
1F3642F0118C8C35008198EF /* sha1.js in Resources */,
1F4673FE1180F7EA006CC37C /* Core.js in Resources */,
8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */,
8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */,
@ -336,6 +331,7 @@
1FFA36D81177D879006C8562 /* ViewDelegate.m in Sources */,
1F77DB47118C5F1C007C7F1E /* Constants.m in Sources */,
1F618ECA12DB5E6100E500D9 /* TweetModel.m in Sources */,
1F245D6F1632AEFE00E4469A /* jso.js in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -6,7 +6,21 @@
// Licence: BSD (see attached LICENCE.txt file).
//
MY_ENTITY = "https://jeena.tent.is";
MY_ENTITY = "http://lala.home.jeena.net:3002";
var app_info = {
"name": "Tentia",
"description": "A small TentStatus client.",
"url": "http://jabs.nu/Tentia/",
"icon": "http://jabs.nu/Tentia/icon.png",
"redirect_uris": [
"tentia://oauthtoken"
],
"scopes": {
"read_posts": "Uses posts to show them in a list",
"write_posts": "Posts on users behalf"
}
};
function getURL(url, type, callback, data) {
$.ajax({
@ -22,7 +36,17 @@ function getURL(url, type, callback, data) {
alert(ajaxOptions);
alert(thrownError);
}
});
});
}
function makeid(len) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < len; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function OauthImplementation() {
@ -35,40 +59,46 @@ OauthImplementation.prototype.requestProfileURL = function (entity) {
getURL(entity, "HEAD", function(resp) {
var headers = resp.getAllResponseHeaders();
var regex = /Link: <([^>]*)>; rel="https:\/\/tent.io\/rels\/profile"/;
var matches = headers.match(regex)
alert(matches[1]);
those.register(matches[1]);
var profile_url = headers.match(regex)[1]
if (profile_url == "/profile") {
profile_url = entity + "/profile";
}
alert(profile_url);
those.register(profile_url);
});
}
OauthImplementation.prototype.register = function (url) {
var app_info = {
"name": "Tentia",
"description": "A small TentStatus client.",
"url": "http://jabs.nu/Tentia/",
"icon": "http://jabs.nu/Tentia/icon.png",
"redirect_uris": [
"tentia://oauth_token"
],
"scopes": {
"read_posts": "Uses posts to show them in a list",
"write_posts": "Posts on users behalf"
}
};
var those = this;
getURL(url, "GET", function(resp) {
var profile = JSON.parse(resp.responseText);
var server = profile["https://tent.io/types/info/core/v0.1.0"]["servers"][0];
var callback = function(resp) {
alert(JSON.parse(resp.responseText));
var data = JSON.parse(resp.responseText);
those.authRequest(server, data);
}
alert(server + "/apps")
getURL(server + "/apps", "POST", callback, JSON.stringify(app_info));
});
}
OauthImplementation.prototype.authRequest = function(server, register_data) {
// id
// mac_key_id
// mac_key
// mac_algorithm
var state = makeid(19);
var auth = "/oauth/authorize?client_id=" + register_data["id"]
+ "&redirect_uri=" + escape(app_info["redirect_uris"][0])
+ "&scope=" + Object.keys(app_info["scopes"]).join(",")
+ "&state=" + state
+ "&tent_post_types=" + escape("https://tent.io/types/posts/status/v0.1.0");
alert(server + auth)
controller.openURL_(server + auth);
}
@ -113,7 +143,11 @@ OauthImplementation.prototype.requestTokenTicketFinished = function(data) {
OauthImplementation.prototype.requestAccessToken = function(responseBody) {
// "twittia://oauth_token?oauth_token=jCcf7ClzJMbE4coZdONi467OAQxRGOBZJsuopG8C8&oauth_verifier=BK2ZkAIz51lqI4qta8MnKc280GyDLy0OQBpdsEmjT40"
alert("XXX");
alert(responseBody);
/*
var urlVars = getUrlVars(responseBody);
var url = OAUTH_ACCESS_TOKEN_URL;
@ -144,7 +178,7 @@ OauthImplementation.prototype.requestAccessToken = function(responseBody) {
alert(ajaxOptions);
alert(thrownError);
}
});
});*/
}
OauthImplementation.prototype.requestAccessTokenTicketFinished = function(responseBody) {

View file

@ -1,27 +1,28 @@
ffffffffffffffffffffffffffffffff 3ddc90c7adbe232b25db27bf9ae28615 ffffffffffffffffffffffffffffffff 102 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app
00000000000000000000000000000000 d3b0bab7e35e3d2ecbe610f54e5c88a5 ffffffffffffffffffffffffffffffff 264643 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/Icon.icns
0000000050783ba000000000000000cc 6b23c46f80bbe095d628a0dd8c50b78c ffffffffffffffffffffffffffffffff 204 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Frameworks/Sparkle.framework
ffffffffffffffffffffffffffffffff 07d4ddde1c7b4b4fee20864dfe87606b ffffffffffffffffffffffffffffffff 125132 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/MacOS/Tentia
ffffffffffffffffffffffffffffffff 7365c3e40e3a8c345e594a3358870afe ffffffffffffffffffffffffffffffff 47308 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/i386/Tentia
ffffffffffffffffffffffffffffffff ed3b6292efc4dffe0e1fdcc298491563 ffffffffffffffffffffffffffffffff 71736 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/Tentia
42acb1866502724ee28245c2f99e565a 2577f0e7533580056a012b1d8c07e8e3 ffffffffffffffffffffffffffffffff 74372 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/Controller.o
d56a7f2949f5e77d95daeff9827e3c0c f52127d6e87cbff0cead9facce224e97 ffffffffffffffffffffffffffffffff 60296 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/i386/Controller.o
00000000000000000000000000000000 c7a2ed34f1b3c3c36f2238612a286b0e ffffffffffffffffffffffffffffffff 7294 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/OauthImplementation.js
0000000050783ba000000000000000cc 6b23c46f80bbe095d628a0dd8c50b78c ffffffffffffffffffffffffffffffff 204 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Frameworks/Sparkle.framework
ffffffffffffffffffffffffffffffff 6711c5d466273f5a792af8d9e1a5319f ffffffffffffffffffffffffffffffff 6456 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/i386/TweetModel.o
ffffffffffffffffffffffffffffffff d72ca303542648087e1ad07182f9d39f ffffffffffffffffffffffffffffffff 9580 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/i386/Constants.o
ffffffffffffffffffffffffffffffff 1ef511a44e75dd4e304fe7498e57eaad ffffffffffffffffffffffffffffffff 24136 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/i386/ViewDelegate.o
ffffffffffffffffffffffffffffffff f52127d6e87cbff0cead9facce224e97 ffffffffffffffffffffffffffffffff 60296 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/i386/Controller.o
ffffffffffffffffffffffffffffffff a6d1a98896876b2874da800beec1af5f ffffffffffffffffffffffffffffffff 2520 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/i386/main.o
ffffffffffffffffffffffffffffffff 6bcdf375b7d539d37a5749532ffc84b5 ffffffffffffffffffffffffffffffff 29928 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/i386/NewMessageWindow.o
ffffffffffffffffffffffffffffffff a97a8adeefed1ba8a895f7136e93dbf0 ffffffffffffffffffffffffffffffff 10692 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/i386/AccessToken.o
00000000006c1f9f000000000000016a d56a7f2949f5fca495daeff9827e3b33 ffffffffffffffffffffffffffffffff 13965516 /var/folders/zl/vphyb36166vg0vnzmz23_y740000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Tentia_Prefix-blwgpqgklakogehapwplzglymvsa/Tentia_Prefix.pch.pth
ffffffffffffffffffffffffffffffff ed3b6292efc4dffe0e1fdcc298491563 ffffffffffffffffffffffffffffffff 71736 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/Tentia
ffffffffffffffffffffffffffffffff 244b8c9ee82cc5939662218150f75171 ffffffffffffffffffffffffffffffff 8624 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/TweetModel.o
ffffffffffffffffffffffffffffffff e1dd691322b6c644d65505d9fd9e9344 ffffffffffffffffffffffffffffffff 11084 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/Constants.o
ffffffffffffffffffffffffffffffff 2a0eeea2e8601206c56722921666610f ffffffffffffffffffffffffffffffff 28012 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/ViewDelegate.o
ffffffffffffffffffffffffffffffff 2577f0e7533580056a012b1d8c07e8e3 ffffffffffffffffffffffffffffffff 74372 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/Controller.o
ffffffffffffffffffffffffffffffff 34c5f6253fd3652602ac9f689caff418 ffffffffffffffffffffffffffffffff 2672 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/main.o
ffffffffffffffffffffffffffffffff 1c94908045430b21b3bd64e63fe2ae06 ffffffffffffffffffffffffffffffff 35572 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/NewMessageWindow.o
ffffffffffffffffffffffffffffffff 0b19471e78e79db38cf65ac8ea0898ec ffffffffffffffffffffffffffffffff 13872 /Users/jeena/Projects/Tentia/build/Tentia.build/Debug/Twittia.build/Objects-normal/x86_64/AccessToken.o
00000000006c1f9f000000000000016a 42acb18665026997e28245c2f99e5165 ffffffffffffffffffffffffffffffff 13379576 /var/folders/zl/vphyb36166vg0vnzmz23_y740000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Tentia_Prefix-ebfofqgutfagnlccnfecejfszpvw/Tentia_Prefix.pch.pth
00000000000000000000000000000000 8aee465c6d1319e6da0148fd63b765fd ffffffffffffffffffffffffffffffff 726 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/index_oauth.html
00000000000000000000000000000000 cc90fbe023b6ad3b1d31bdcece689545 ffffffffffffffffffffffffffffffff 630 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/pin.png
00000000000000000000000000000000 d3b0bab7e35e3d2ecbe610f54e5c88a5 ffffffffffffffffffffffffffffffff 121861 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/Icon.icns
00000000000000000000000000000000 461f981fcc74c67c6a4c4118e66a23ce ffffffffffffffffffffffffffffffff 11868 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/sprite-icons.png
00000000000000000000000000000000 a0807f75cabb63b870a3a7b7ea3b4eea ffffffffffffffffffffffffffffffff 3002 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/default.css
00000000000000000000000000000000 54f84f996cfd6998112e0864b3a219a5 ffffffffffffffffffffffffffffffff 72174 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/jQuery.js
@ -37,7 +38,6 @@ ffffffffffffffffffffffffffffffff 0b19471e78e79db38cf65ac8ea0898ec ffffffffffffff
00000000000000000000000000000000 ea6df34316ae4b4a2b0a04e0ea2b7541 ffffffffffffffffffffffffffffffff 5550 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/sha1.js
00000000000000000000000000000000 c5fc2a371798c0a6995845e5185b1605 ffffffffffffffffffffffffffffffff 20756 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/oauth.js
00000000000000000000000000000000 f046752ea2d26acc574f55553b495770 ffffffffffffffffffffffffffffffff 1178 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/dsa_pub.pem
00000000000000000000000000000000 c7a2ed34f1b3c3c36f2238612a286b0e ffffffffffffffffffffffffffffffff 6253 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/OauthImplementation.js
00000000000000000000000000000000 5574e00c2add45a7d40448dc5ebe5186 ffffffffffffffffffffffffffffffff 607 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Resources/Constants.js
00000000000000000000000000000000 c674cff473d4e9e23616ac3a869f2f2d ffffffffffffffffffffffffffffffff 8 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/PkgInfo
00000000000000000000000000000000 c674cff473d4e9e23616ac3a869f2f2d ffffffffffffffffffffffffffffffff 2494 /Users/jeena/Projects/Tentia/build/Debug/Tentia.app/Contents/Info.plist

File diff suppressed because one or more lines are too long

View file

@ -7,8 +7,7 @@
<link rel="stylesheet" href="~/Library/Application%20Support/Style.css" type="text/css" />
<script type="text/javascript" src="jQuery.js"></script>
<script type="text/javascript" src="jQuery-Plugins.js"></script>
<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript" src="oauth.js"></script>
<script type="text/javascript" src="jso.js"></script>
<script type="text/javascript" src="Constants.js"></script>
<script type="text/javascript" src="Core.js"></script>
</head>

View file

@ -5,8 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="jQuery.js"></script>
<script type="text/javascript" src="jQuery-Plugins.js"></script>
<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript" src="oauth.js"></script>
<script type="text/javascript" src="jso.js"></script>
<script type="text/javascript" src="Constants.js"></script>
<script type="text/javascript" src="OauthImplementation.js"></script>
</head>

613
jso.js Normal file
View file

@ -0,0 +1,613 @@
(function(exp, $) {
var
config = {},
default_lifetime = 3600,
options = {
"debug": false
},
api_redirect,
Api_default_storage,
api_storage,
internalStates = [];
/*
* ------ SECTION: Utilities
*/
/*
* Returns a random string used for state
*/
var uuid = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
/**
* A log wrapper, that only logs if logging is turned on in the config
* @param {string} msg Log message
*/
var log = function(msg) {
if (!options.debug) return;
if (!console) return;
if (!console.log) return;
// console.log("LOG(), Arguments", arguments, msg)
if (arguments.length > 1) {
console.log(arguments);
} else {
console.log(msg);
}
}
/**
* Set the global options.
*/
var setOptions = function(opts) {
if (!opts) return;
for(var k in opts) {
if (opts.hasOwnProperty(k)) {
options[k] = opts[k];
}
}
log("Options is set to ", options);
}
/*
* Takes an URL as input and a params object.
* Each property in the params is added to the url as query string parameters
*/
var encodeURL = function(url, params) {
var res = url;
var k, i = 0;
var firstSeparator = (url.indexOf("?") === -1) ? '?' : '&';
for(k in params) {
res += (i++ === 0 ? firstSeparator : '&') + encodeURIComponent(k) + '=' + encodeURIComponent(params[k]);
}
return res;
}
/*
* Redirects the user to a specific URL
*/
api_redirect = function(url) {
window.location = url;
};
Api_default_storage = function() {
log("Constructor");
};
/**
saveState stores an object with an Identifier.
TODO: Ensure that both localstorage and JSON encoding has fallbacks for ancient browsers.
In the state object, we put the request object, plus these parameters:
* restoreHash
* providerID
* scopes
*/
Api_default_storage.prototype.saveState = function (state, obj) {
localStorage.setItem("state-" + state, JSON.stringify(obj));
}
/**
* getStage() returns the state object, but also removes it.
* @type {Object}
*/
Api_default_storage.prototype.getState = function(state) {
// log("getState (" + state+ ")");
var obj = JSON.parse(localStorage.getItem("state-" + state));
localStorage.removeItem("state-" + state)
return obj;
};
/*
* Checks if a token, has includes a specific scope.
* If token has no scope at all, false is returned.
*/
Api_default_storage.prototype.hasScope = function(token, scope) {
var i;
if (!token.scopes) return false;
for(i = 0; i < token.scopes.length; i++) {
if (token.scopes[i] === scope) return true;
}
return false;
};
/*
* Takes an array of tokens, and removes the ones that
* are expired, and the ones that do not meet a scopes requirement.
*/
Api_default_storage.prototype.filterTokens = function(tokens, scopes) {
var i, j,
result = [],
now = epoch(),
usethis;
if (!scopes) scopes = [];
for(i = 0; i < tokens.length; i++) {
usethis = true;
// Filter out expired tokens. Tokens that is expired in 1 second from now.
if (tokens[i].expires && tokens[i].expires < (now+1)) usethis = false;
// Filter out this token if not all scope requirements are met
for(j = 0; j < scopes.length; j++) {
if (!api_storage.hasScope(tokens[i], scopes[j])) usethis = false;
}
if (usethis) result.push(tokens[i]);
}
return result;
};
/*
* saveTokens() stores a list of tokens for a provider.
Usually the tokens stored are a plain Access token plus:
* expires : time that the token expires
* providerID: the provider of the access token?
* scopes: an array with the scopes (not string)
*/
Api_default_storage.prototype.saveTokens = function(provider, tokens) {
// log("Save Tokens (" + provider+ ")");
localStorage.setItem("tokens-" + provider, JSON.stringify(tokens));
};
Api_default_storage.prototype.getTokens = function(provider) {
// log("Get Tokens (" + provider+ ")");
var tokens = JSON.parse(localStorage.getItem("tokens-" + provider));
if (!tokens) tokens = [];
log("Token received", tokens)
return tokens;
};
Api_default_storage.prototype.wipeTokens = function(provider) {
localStorage.removeItem("tokens-" + provider);
};
/*
* Save a single token for a provider.
* This also cleans up expired tokens for the same provider.
*/
Api_default_storage.prototype.saveToken = function(provider, token) {
var tokens = this.getTokens(provider);
tokens = api_storage.filterTokens(tokens);
tokens.push(token);
this.saveTokens(provider, tokens);
};
/*
* Get a token if exists for a provider with a set of scopes.
* The scopes parameter is OPTIONAL.
*/
Api_default_storage.prototype.getToken = function(provider, scopes) {
var tokens = this.getTokens(provider);
tokens = api_storage.filterTokens(tokens, scopes);
if (tokens.length < 1) return null;
return tokens[0];
};
api_storage = new Api_default_storage();
/*
* ------ SECTION: Utilities
*/
/*
* Returns a random string used for state
*/
var uuid = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
/*
* Takes an URL as input and a params object.
* Each property in the params is added to the url as query string parameters
*/
var encodeURL = function(url, params) {
var res = url;
var k, i = 0;
for(k in params) {
res += (i++ === 0 ? '?' : '&') + encodeURIComponent(k) + '=' + encodeURIComponent(params[k]);
}
return res;
}
/*
* Returns epoch, seconds since 1970.
* Used for calculation of expire times.
*/
var epoch = function() {
return Math.round(new Date().getTime()/1000.0);
}
var parseQueryString = function (qs) {
var e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&;=]+)=?([^&;]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = qs,
urlParams = {};
while (e = r.exec(q))
urlParams[d(e[1])] = d(e[2]);
return urlParams;
}
/*
* ------ / SECTION: Utilities
*/
/**
* Check if the hash contains an access token.
* And if it do, extract the state, compare with
* config, and store the access token for later use.
*
* The url parameter is optional. Used with phonegap and
* childbrowser when the jso context is not receiving the response,
* instead the response is received on a child browser.
*/
exp.jso_checkfortoken = function(providerID, url, callback) {
var
atoken,
h = window.location.hash,
now = epoch(),
state,
co;
log("jso_checkfortoken(" + providerID + ")");
// If a url is provided
if (url) {
// log('Hah, I got the url and it ' + url);
if(url.indexOf('#') === -1) return;
h = url.substring(url.indexOf('#'));
// log('Hah, I got the hash and it is ' + h);
}
/*
* Start with checking if there is a token in the hash
*/
if (h.length < 2) return;
if (h.indexOf("access_token") === -1) return;
h = h.substring(1);
atoken = parseQueryString(h);
if (atoken.state) {
state = api_storage.getState(atoken.state);
} else {
if (!providerID) {throw "Could not get [state] and no default providerid is provided.";}
state = {providerID: providerID};
}
if (!state) throw "Could not retrieve state";
if (!state.providerID) throw "Could not get providerid from state";
if (!config[state.providerID]) throw "Could not retrieve config for this provider.";
co = config[state.providerID];
/**
* If state was not provided, and default provider contains a scope parameter
* we assume this is the one requested...
*/
if (!atoken.state && co.scope) {
state.scopes = co.scope;
log("Setting state: ", state);
}
log("Checking atoken ", atoken, " and co ", co);
/*
* Decide when this token should expire.
* Priority fallback:
* 1. Access token expires_in
* 2. Life time in config (may be false = permanent...)
* 3. Specific permanent scope.
* 4. Default library lifetime:
*/
if (atoken["expires_in"]) {
atoken["expires"] = now + parseInt(atoken["expires_in"], 10);
} else if (co["default_lifetime"] === false) {
// Token is permanent.
} else if (co["default_lifetime"]) {
atoken["expires"] = now + co["default_lifetime"];
} else if (co["permanent_scope"]) {
if (!api_storage.hasScope(atoken, co["permanent_scope"])) {
atoken["expires"] = now + default_lifetime;
}
} else {
atoken["expires"] = now + default_lifetime;
}
/*
* Handle scopes for this token
*/
if (atoken["scope"]) {
atoken["scopes"] = atoken["scope"].split(" ");
} else if (state["scopes"]) {
atoken["scopes"] = state["scopes"];
}
api_storage.saveToken(state.providerID, atoken);
if (state.restoreHash) {
window.location.hash = state.restoreHash;
} else {
window.location.hash = '';
}
log(atoken);
if (internalStates[atoken.state] && typeof internalStates[atoken.state] === 'function') {
// log("InternalState is set, calling it now!");
internalStates[atoken.state]();
delete internalStates[atoken.state];
}
if (typeof callback === 'function') {
callback();
}
// log(atoken);
}
/*
* A config object contains:
*/
var jso_authrequest = function(providerid, scopes, callback) {
var
state,
request,
authurl,
co;
if (!config[providerid]) throw "Could not find configuration for provider " + providerid;
co = config[providerid];
log("About to send an authorization request to [" + providerid + "]. Config:")
log(co);
state = uuid();
request = {
"response_type": "token"
};
request.state = state;
if (callback && typeof callback === 'function') {
internalStates[state] = callback;
}
if (co["redirect_uri"]) {
request["redirect_uri"] = co["redirect_uri"];
}
if (co["client_id"]) {
request["client_id"] = co["client_id"];
}
if (scopes) {
request["scope"] = scopes.join(" ");
}
authurl = encodeURL(co.authorization, request);
// We'd like to cache the hash for not loosing Application state.
// With the implciit grant flow, the hash will be replaced with the access
// token when we return after authorization.
if (window.location.hash) {
request["restoreHash"] = window.location.hash;
}
request["providerID"] = providerid;
if (scopes) {
request["scopes"] = scopes;
}
log("Saving state [" + state+ "]");
log(JSON.parse(JSON.stringify(request)));
api_storage.saveState(state, request);
api_redirect(authurl);
};
exp.jso_ensureTokens = function (ensure) {
var providerid, scopes, token;
for(providerid in ensure) {
scopes = undefined;
if (ensure[providerid]) scopes = ensure[providerid];
token = api_storage.getToken(providerid, scopes);
log("Ensure token for provider [" + providerid + "] ");
log(token);
if (token === null) {
jso_authrequest(providerid, scopes);
}
}
return true;
}
exp.jso_findDefaultEntry = function(c) {
var
k,
i = 0;
if (!c) return;
log("c", c);
for(k in c) {
i++;
if (c[k].isDefault && c[k].isDefault === true) {
return k;
}
}
if (i === 1) return k;
};
exp.jso_configure = function(c, opts) {
config = c;
setOptions(opts);
try {
var def = jso_findDefaultEntry(c);
log("jso_configure() about to check for token for this entry", def);
exp.jso_checkfortoken(def);
} catch(e) {
log("Error when retrieving token from hash: " + e);
window.location.hash = "";
}
}
exp.jso_dump = function() {
var key;
for(key in config) {
log("=====> Processing provider [" + key + "]");
log("=] Config");
log(config[key]);
log("=] Tokens")
log(api_storage.getTokens(key));
}
}
exp.jso_wipe = function() {
var key;
log("jso_wipe()");
for(key in config) {
log("Wipping tokens for " + key);
api_storage.wipeTokens(key);
}
}
exp.jso_getToken = function(providerid, scopes) {
var token = api_storage.getToken(providerid, scopes);
if (!token) return null;
if (!token["access_token"]) return null;
return token["access_token"];
}
exp.jso_registerRedirectHandler = function(callback) {
api_redirect = callback;
};
exp.jso_registerStorageHandler = function(object) {
api_storage = object;
};
/*
* From now on, we only perform tasks that require jQuery.
* Like adding the $.oajax function.
*/
if (typeof $ === 'undefined') return;
$.oajax = function(settings) {
var
allowia,
scopes,
token,
providerid,
co;
providerid = settings.jso_provider;
allowia = settings.jso_allowia || false;
scopes = settings.jso_scopes;
token = api_storage.getToken(providerid, scopes);
co = config[providerid];
// var successOverridden = settings.success;
// settings.success = function(response) {
// }
var errorOverridden = settings.error || null;
var performAjax = function() {
// log("Perform ajax!");
if (!token) throw "Could not perform AJAX call because no valid tokens was found.";
if (co["presenttoken"] && co["presenttoken"] === "qs") {
// settings.url += ((h.indexOf("?") === -1) ? '?' : '&') + "access_token=" + encodeURIComponent(token["access_token"]);
if (!settings.data) settings.data = {};
settings.data["access_token"] = token["access_token"];
} else {
if (!settings.headers) settings.headers = {};
settings.headers["Authorization"] = "Bearer " + token["access_token"];
}
$.ajax(settings);
};
settings.error = function(jqXHR, textStatus, errorThrown) {
log('error(jqXHR, textStatus, errorThrown)');
log(jqXHR);
log(textStatus);
log(errorThrown);
if (jqXHR.status === 401) {
log("Token expired. About to delete this token");
log(token);
api_storage.wipeTokens(providerid);
}
if (errorOverridden && typeof errorOverridden === 'function') {
errorOverridden(jqXHR, textStatus, errorThrown);
}
}
if (!token) {
if (allowia) {
log("Perform authrequest");
jso_authrequest(providerid, scopes, function() {
token = api_storage.getToken(providerid, scopes);
performAjax();
});
return;
} else {
throw "Could not perform AJAX call because no valid tokens was found.";
}
}
performAjax();
};
})(window, window.jQuery);