FrontPageairfare-portland-111UserPreferencesdelta-airlines-extra-baggage-271 › UsingOpenID+OAuthFromGoogle
Using OpenID+OAuth From Google
 
FrontPageairfare-portland-111UserPreferencesdelta-airlines-extra-baggage-271 › UsingOpenID+OAuthFromGoogle
테스트 중인 사이트에서 구글을 통한 로그인을 생각했었는데 이번기회에 기대하지 않았던 부분까지 많이 알게 되었다. 원래 계획되로라면 openid인증만 하면 됐었는데 공개된 openid php 라이브러리중에 인증을 못하거나 원하는 request값을 받지 못하였다.

그중에 jarain에서 배포하는 [http]라이브러리로 작업을해서 인증까지 성공을 했는데 인증만 했을뿐 최소한의 사용자 정보(이름이나, 아이디 등)를 제공을 하지 못하였다.(내가 방법을 몰라서 그럴지도 모른다.) 이 라이브러리로 구글인증받고 인증받은 사용자 이름으로 서비스 구축 하는 시스템을 만들려고 했을 뿐이였는데 너무 깊게 와버렸다. 이번기회에 ouath라는 서비스를 알게 되고 그동안 신경 쓰지 않은 zend라이브러리 삽질도 하게 되었다.

이번 작업을 하면서 느끼게 된것은 ouath관련 정보가 국내에는 너무 부족하다. oauth에 관한 소개나 뉴스정보는 많이 보게 되었는데 실제 적용한 사례, 셈플 찾기가 너무 어려웠다. 그 중에 oauth에 대한 개념을 많이 알게된 사이트는 오픈마루와 딥블루님의 블로그를 통해 많이 배우게 되었다.

여기서는 hybrid라이브러리를 통해 구현을 해 보겠다. ([http]demo)

To register a new domain #

개념을 이해하는데는 위의 린크에 설명이 잘 되어있기 때문에 따로 설명은 하지 않겠다. 여기서 시도 해볼 것은 현재 사이트에서 구글 로그인 인증을 받고 구글 서비스 받는 방법을 소개하겠다.

openid와 달리 oauth인증은 생각보다 복잡했다 그중에 내가 제일 헤메던 부분은 프로바이더 사이트에 컨수머 키를 발급 받는 과정을 모르고 openid와 같은 방식으로 계속 접속시도만 했었다는거다.

1.Add your domain.

Under the heading "Add a New Domain", enter the URL for your domain and click the "Add Domain" button. A new link for the domain is added under the "Manage Registrations" heading. You can register up to eight different domains using one Google account. At this point in the process, your domain has been identified but not yet registered.
Manage your domains에서 사이트를 등록한다. 그리고 Manage registration에서 등록한 사이트를 선택해준다.

2. Verify your domain.

Under the heading "Manage Registrations", click on the link for the domain you just added. The interface walks you through the process of verifying that you have administrator access to the domain. Choose between one of two verification methods: upload an HTML file or add a specific meta tag to your home page.

  • Uploading a file: With this method, Google specifies a file name starting with "google". Create an empty file with this name, using the html extension, and upload it to your domain. Be sure to place the file at the domain root. Check that the new file has been published, and return to the Manage Your Domains page for this domain. Click the "Verify" button. If you are unable to verify using this method (for example, there may be a conflict with your web server configuration), use the meta tag method.
  • Adding a meta tag: With this method, Google specifies a tag to be added to your domain's home page. Add the tag anywhere in the section of the page and upload it to your domain. Check that the new file has been published, and return to the Manage Your Domains for this domain. Click the "Verify" button.
해당 홈페이지를 인증해주는 과정인데 나는 루트폴더에 파일을 추가하는 방식을 선택했다.

3. Provide domain information.

Once you've accepted the terms of service, Google requests two pieces of information to complete registration:

  • Target URL path prefix: This value enables Google to reject all authorization requests ostensibly from your domain that use an incorrect domain or prefix. If you're making an AuthSub request, this URL must be identical to the prefix value of the next parameter used in your authorization requests. For example, if your next values will be something like http://example.com/authsub and/or http://example.com/feed/authsub, your prefix should be http://example.com. If you're using the OAuth interface, this URL must match the value of the oauth_consumer_key parameter.
  • Domain description: This optional value should briefly describe the domain you're registering. In the future, this description may be displayed on the Google Access Consent page to provide additional information for your users. You always have the option of changing this description or leaving it blank.
여기가 커슈마키와 시크릿을 발급 받는 부분이다. path지정하는 부분이 나중에 구글쪽에서 보네오는 인증관련 데이타를 받고 처리해주는 부분이다. 나는 샘플과 동일하게 acooda.dyndns.org/authsub으로 설정했다.
설정하고나면 커슈머키와 시크릿을 출력해주는데 그것을 잘 적어놓자.

5. 암호화 관련부분은 패스 하였다 우리가 HMAC-SHA1 방식을 쓰는 정도로만 알고 있자.

Hybrid Protocol (OpenID + OAuth) #

이제 로그인과 인증과 리퀘스트 토큰 처리해주는 라이브러리를 설치해보자. 여기서 사용한 라이브러리는 구글에서 제공하는 라이브러리를 사용하였다.

1. svn을 통해 다운로드 받는다.
svn co http://code.google.com/p/gdata-samples/source/browse/svn/trunk/hybrid hybrid

2. 다운로드 바든 소스는 웹서버 홈디렉토리에 설치했다고 가정하겠다.
/var/www/hybrid/<소스>

3. hybrid라이브러리는 zend라이브러리를 필요로 한다. 이것도 svn을 통해 다운로드 받자.
svn co http://framework.zend.com/svn/framework/standard/trunk/library/Zend/ Zend

4. 다운받은 zend라이브러리는 hybryd디렉토리 안에다 위치해준다.
/var/www/hybrid/Zend/<소스>

5. hybrid디렉토리에서 index.php파일을 수정하자. 여기에는 zend라이브러리 path와 커슈머 키와, 시크릿 설정을 할 것이다.
index.php
$a='.' . PATH_SEPARATOR . '/var/www/hybrid/'
       . PATH_SEPARATOR . get_include_path();
set_include_path($a); //hybrid디렉토리를 path설정 해준다.
                              //설정 안해주면 zend라이브러리 불러오는 과정에서
                              //에러가 날 것이다.

session_start();

// OAuth/OpenID libraries and utility functions.
require_once 'common.inc.php';

// Load the necessary Zend Gdata classes.
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_HttpClient');
Zend_Loader::loadClass('Zend_Gdata_Docs');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');

// Setup OAuth consumer with our "credentials"
$CONSUMER_KEY = 'acooda.dyndns.org';  //구글에서 받은 키와 시크릿값을 넣어주자
$CONSUMER_SECRET = 'VPhXT9u75tld8/tidO2r3XhW';
$consumer = new OAuthConsumer($CONSUMER_KEY, $CONSUMER_SECRET);
6. 이젠 구글에서 인증 받을때 리퀘스트 처리해줄 수 있게 rewrite설정을 해보자. 아파치에 rewirte설정이 안되있으면 mod_rewrite를 참고하자.
7. 홈 디렉토리에 authsub파일을 생성하고 아래 소스를 넣어준다.
<?php
chdir
("/var/www/openid/hybrid/");
include(
"index.php");
?>
8. .htaccess파일을 수정해준다.
<Files authsub>
  ForceType application/x-httpd-php
</Files>
9. 이제 http://acooda.dyndns.org/authsub 로 접속해서 확인해본다.

관련 린크 #

acooda.com