2012-01-18 9 views
2

私は(正確にはJomSocial)、そこから特定の情報を取得するのJoomlaを実行しているWebサイトに接続するiPhoneアプリケーションを書いています使用してのJoomlaで認証する必要があります。 私は完全にこれらの最後の日に詰まっている認証プロセスです。 私はWeb/PHPのエキスパートではなく(基本を知っているだけです)、初めてJoomlaプラットフォームと組み合わせて開発しています。iPhoneアプリはASIHTTPRequest

シナリオ:ユーザがログインするログインフォーム(ユーザ名/パスワード/覚え書き)を持つウェブサイトがあります。 iPhoneで、ユーザがアプリを起動し、2つのUITextFields、1つはユーザー名用、もう1つはパスワード用です。また、認証を進め、以下に掲示されたメソッドを呼び出すためのボタンがあります。 ユーザーが必要なフィールドを入力すると、アプリは覚えているボタンとみなし、ログアウトボタンが押されるまで認証されたまま認証を続けます。 、私はウェブサイト上の情報を送信するためにASIHTTPRequest APIを実装していますことを行うには

。認証メソッドのコードは次のとおりです。requestFinishedから

- (void)performAuthentication 
{ 
    NSURL *url = [NSURL URLWithString:@"http://mywebsite.com/index.php?option=com_community"]; 

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
    [request setDelegate:self]; 

    [request setUseKeychainPersistence:YES]; 
    [request setUseCookiePersistence:YES]; 
    [request setUseSessionPersistence:YES]; 
    [request setShouldAttemptPersistentConnection:YES]; 

    [request setRequestMethod:@"POST"]; 
    [request setUserAgent:@"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3"]; //does not matter, I was just trying it 
    [request setTimeOutSeconds:20]; 

    //main login options - user fills in 
    [request setPostValue:emailText.text forKey:@"username"]; 
    [request setPostValue:passwordText.text forKey:@"passwd"]; 
    [request setPostValue:@"yes" forKey:@"remember"]; 

    //secondary options derived from string 
    [request setPostValue:@"Log+in" forKey:@"submit"]; 
    [request setPostValue:@"com_user" forKey:@"option"]; 
    [request setPostValue:@"login" forKey:@"task"]; 

    [request startAsynchronous]; 
} 

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSLog(@"STATUS CODE: %i", [request responseStatusCode]); 
    NSLog(@"STATUS MESSAGE: %@", [request responseStatusMessage]); 
    NSLog(@"HEADERS: %@", [request responseHeaders]); 
} 

- (void)requestFailed:(ASIHTTPRequest *)request 
{ 
    NSError *error = [request error]; 
    NSLog(@"Error = %@", error); 
} 

結果は以下のとおりです。私は

POST /index.php?option=com_community HTTP/1.1 
Host: mywebsite.com 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en;q=0.5 
Accept-Encoding: gzip, deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
DNT: 1 
Connection: keep-alive 
Referer: http://mywebsite.com/index.php 
Cookie: referrerid=AUPRR-4F16C6005781D; currentURI=http%3A%2F%2Fmywebsite.com%2Findex.php; 5ddfdbeb767d245c52d97fea9c4ba768=92a78d2faee8e9029d29d56d5d5270dc; activeProfile=90 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 256 
username=my_user&passwd=my_pass&submit=log+in&option=com_user&task=login&return=L2luZGV4LnBocD9vcHRpb249Y29tX2NvbW11bml0eSZ2aWV3PWZyb250cGFnZSZJdGVtaWQ9MzM%3D&3946e5e25450d1a242ceffbd96ea8733=1&remember=yes 

HTTP/1.1 303 See other 
Date: Wed, 18 Jan 2012 13:29:13 GMT 
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/1.0.0-fips mod_bwlimited/1.4 mod_perl/2.0.5 Perl/v5.10.1 
X-Powered-By: PHP/5.2.17 
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM" 
Set-Cookie: 5ddfdbeb767d245c52d97fea9c4ba768=bff8a2f942f8e23633a8816cd36de1cb; path=/ 
Set-Cookie: activeProfile=90; expires=Wed, 18-Jan-2012 13:44:13 GMT; path=/ 
Set-Cookie: afcee664c0a8fd2cd6ff5cc9df8eab30=51+9+2+218475F+A+216444A5C165F505456145D115F535B+31011+74350+25455405D78+459+45B541A52565446+A42+3+B+C4412+411114E5D13+613+212+2+7+912+951+715+2+1+C13+244; expires=Thu, 17-Jan-2013 13:29:13 GMT; path=/ 
Location: http://mywebsite.com/index.php?option=com_community 
Content-Length: 0 
Keep-Alive: timeout=5, max=100 
Connection: Keep-Alive 
Content-Type: text/html 

」:

2012-01-18 17:15:48.850 MyApp[3500:f803] STATUS CODE: 200 
2012-01-18 17:15:48.850 MyApp[3500:f803] STATUS MESSAGE: HTTP/1.1 200 OK 
2012-01-18 17:15:48.851 MyApp[3500:f803] HEADERS: 
{ 
    "Cache-Control" = "post-check=0, pre-check=0"; 
    Connection = close; 
    "Content-Type" = "text/html; charset=utf-8"; 
    Date = "Wed, 18 Jan 2012 15:15:51 GMT"; 
    Expires = "Mon, 1 Jan 2001 00:00:00 GMT"; 
    "Last-Modified" = "Wed, 18 Jan 2012 15:15:51 GMT"; 
    P3P = "CP=\"NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM\""; 
    Pragma = "no-cache"; 
    Server = "Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/1.0.0-fips mod_bwlimited/1.4 mod_perl/2.0.5 Perl/v5.10.1"; 
    "Set-Cookie" = "currentURI=http%3A%2F%mywebsite.com%2Findex.php%3Foption%3Dcom_community; expires=Thu, 19-Jan-2012 15:15:51 GMT; path=/"; 
    "Transfer-Encoding" = Identity; 
    "X-Powered-By" = "PHP/5.2.17"; 
} 

livehttpheadersアドオンでFirefoxを使用して、私はこれを取得しますM直面3つの問題:私は

  1. 303の代わりに200応答コードを取得すると、livehttpheadersが示します。
  2. activeProfileという名前のクッキーは、クッキーのストレージに保存されていないようです。それは、各認証にランダムであり、私はそれで何をするか分からないよう
  3. のContent-Lengthレスポンスの長いトークンは(livehttpheader出力に示すように)使用することはできません。

一般に、認証方法は接続しますが、プロセスは実行されず、残りは標準のhttpアクセスのCookieです。私はウェブサイトのアドレスをUIWebViewをロードして確認することができます。ユーザーがログインしていないことがわかります。

私はWebエキスパートではありませんが(特定のことを理解することはできますが)、Joomlaの認証時間。 誰かが似たようなことに直面していて、道を見つけたのかどうか疑問に思います。 アイデアやアドバイスは大変ありがとうございます。

ありがとう;)

答えて

0

はちょうどあなたがあなたのコード内の任意のHttpHeadersを設定されていません気づきました。 Joomlaヘッダーに一致するはずのHttpHeadersを確認してください。

+0

はい、私はそれを試してみました。送信されたがまだ認証されていないすべてのヘッダーを追加しました。 – Pericles