Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9986] CLI: "login, logout" builtin

GitHub Issuen/a
TypeSub-task
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-09-13T15:38:04.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.0.0, Sprint 2012-19 JS, 2012 Sprint 19
ComponentsCLI
Labelsn/a
ReporterChris Barber
AssigneeChris Barber
Created2012-07-17T01:54:45.000+0000
Updated2017-03-08T00:41:11.000+0000

Description

Logs a user into and out of the Appcelerator Network. Session cookie and user info (not sure what info... whatever app-track requires) to be written to ~/.titanium/session.json (or something). Need to tie into --user and --password options (currently wired up, but disabled). Not sure how to check if a session is valid. Not sure if we should persist credentials. Here's an example curl command:
curl https://api.appcelerator.net/p/v1/sso-login -v -d "un=user@domain.com" -d "pw=123123" -d "mid=1eagg1a3eg1gea1gae1gea1g2e1"
Which produces:
* About to connect() to api.appcelerator.net port 443 (#0)
*   Trying 107.21.236.169...
* connected
* Connected to api.appcelerator.net (107.21.236.169) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES256-SHA
* Server certificate:
* 	 subject: O=*.appcelerator.net; OU=Domain Control Validated; CN=*.appcelerator.net
* 	 start date: 2011-10-13 21:14:23 GMT
* 	 expire date: 2013-10-13 21:14:23 GMT
* 	 subjectAltName: api.appcelerator.net matched
* 	 issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certificates.godaddy.com/repository; CN=Go Daddy Secure Certification Authority; serialNumber=07969287
* 	 SSL certificate verify ok.
> POST /p/v1/sso-login HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: api.appcelerator.net
> Accept: */*
> Content-Length: 69
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 69 out of 69 bytes
< HTTP/1.1 200 OK
< Access-Control-Allow-Methods: POST, GET, OPTIONS
< Cache-Control: private
< Content-Type: application/json;charset=utf-8
< Date: Tue, 11 Sep 2012 18:52:50 GMT
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Pragma: no-cache
< Server: Apache/2.2.14 (Ubuntu)
< Set-Cookie: PHPSESSID=ob6jvsgjmpqa8uod909te6ksd6; path=/; domain=.appcelerator.net
< Vary: Accept-Encoding
< X-Powered-By: PHP/5.3.2-1ubuntu4.14
< Content-Length: 1603
< Connection: keep-alive
< 
* Connection #0 to host api.appcelerator.net left intact
{"success":true,"sid":"2e2ecb2f2c5ceaa5f8fda590fb17751443e4db96","token":"00000000","uid":"000000","guid":"000000d05b4ca309776ba80694b43557","uidt":"000000ea11b7f1b4660df54d4d46d2695d9ec724","activated":true,"uguid":"000000000000000000000000","email":"user@domain.com","permissions":{"mobilesdk":"enabled","is-admin":"enabled","premium-support":"enabled","is-staff":"enabled"},"attributes":{"account-confirm-date":"2010-06-27 12:38:36","interested_in":null,"specialties":"40,5","platform_experience":"18,17","programming_langs":"33,28,27,30","profile_completeness":"100","department":"4","supervisor":"1322484","date-of-employment":"6\/28\/2010","time-zone":"5","irc-nickname":"cb1kenobi","projects":"14,15,16,4","skype":"cb1kenobi","double_trigger_survey":"1","firstname":"Chris","lastname":"Barber","organization":"Appcelerator","phone":"000-000-0000","title":"Engineer","city":"Testville","postalcode":"00000","country":"US","bio":"I build cool stuff for Appcelerator.","titanium_appcount":"","twitter":"","facebook":"","linkedin":"","portfolio_url":"http:\/\/www.appcelerator.com\/","developer_role":"12","develops_for":"48","tech_level":"26","titanium_proficiency":"26","state":"CA"},"plans":[{"org_id":00000,"role_id":"1","current-plan_id":4000,"current-product_id":"4006"},{"org_id":14301,"role_id":"11","current-plan_id":4000,"current-product_id":"4006"}],"community":"false","plans_data":"http:\/\/api.appcelerator.net\/p\/v1\/plans-data?token=0000000000","session_allowed_duration":72}* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
Here's an example in Titanium code that would need to be ported to node.js:
function networkLogin(username, password, success, error) {
	var xhr = Ti.Network.createHTTPClient();

	//Parity issue: iOS fires onload for 4xx and 3xx status codes, so need to manually check onload
	xhr.onload = function() {
		if (xhr.status == 200) {
			//return the session ID to store in ACS
			var cookies = xhr.getResponseHeader('Set-Cookie'),
				sessionId = '';
			_.each(cookies.split(';'), function(cookie) {
				var parts = cookie.split('=');
				if (parts[0].indexOf('PHPSESSID') >= 0) {
					sessionId = parts[1];
				}
			});
			success(sessionId);
		}
		else {
			error();
		}
		Ti.API.info('Status Code: '+ xhr.status);
		Ti.API.info('Set-Cookie: '+ xhr.getResponseHeader('Set-Cookie'));
	};
	
	xhr.onerror = error;
	
	xhr.open('POST', 'https://api.appcelerator.net/p/v1/sso-login');
	xhr.send({
		un:username,
		pw:password,
		mid:Ti.Platform.id
	});
}

Comments

  1. Bryan Hughes 2012-09-13

    Pull Requests: https://github.com/appcelerator/node-appc/pull/1 https://github.com/appcelerator/titanium/pull/4
  2. Lee Morris 2017-03-08

    Closing ticket as resolved.

JSON Source