블로그 이미지
윤영식
Full Stacker, Application Architecter, KnowHow Dispenser and Bike Rider

Publication

Category

Recent Post

2013. 10. 6. 21:09 Protocols/OAuth

플랫폼의 핵심 기능중 하나가 Open API이다. 해당 기능을 이용하려면 인증(Authetication)하고 권한 부여(Authorization)할 수 있는 약속을(프로토콜) 새롭게 만들어야 했고 그 결과물이 OAuth이다. 초기 1.0에서 보안결함을 해결한 1.0a 와 최신 2.0 버전을 가장 많이 사용을 하고 있다. 




개념

예전의 OpenID방식은 인증(로그인)만을 처리하는 것이고, RESTful Open API 호출시 권한 체크를 하지 않으므로 이에 대한 권한체크도 필요하다. OAuth는 두개의 역할을 다 수행한다 

  - 인증 : 우리가 흔히 사용하는 Login시 ID/Password 를 통하여 인증을 받는다 - Request_Token

  - 권한 : 권한이 있는 기능만을 호출할 수 있다 - Access_Token



버전

  - v1.0 : 보안 결함 발견 v1.0a가 IETF 표준 프로토콜, 웹만 인증 가능

  - v2.0 : v1.0의 key_signature 복잡함등의 제거, 웹뿐만 아니라 애플리케이션도 인증 가능 



V1.0 

  - User : 특정 서비스에 사용하는 유저 예) Smart Visualization 사용자

    Consumer : 특정 서비스이면서 OAuth 제공자(서비스 제공자)에게 인증과 권한을 요청 예) Smart Visualization

    Service Provider : OAuth 제공자 예) 트위터

  


  - Request Token 으로 인증을 처리하고 Access Token으로 권한

  - 장점

1. 컨슈머가 아이디/패스워드를 가지지 않고 API를 사용할 수 있음

2. 필요한 API에만 제한적으로 접근할 수 있도록 권한 제어 가능

3. 사용자가 서비스 프로바이더의 관리 페이지에서 권한 취소 가능

4. 패스워드 변경 시에도 인증 토큰은 계속 유효함.

  - 총정리

  
- 동영상 강좌 
  


  

V2.0 

  - 3가지 종류 존재 : bearer token 방식 사용. 나머지 두가지는 계속 수정중 

  - 간단해 졌고, 더 많은 인증 방법을 제공, 대형 서비스로 확장을 지원한다 

  


사용하기 

  - 다양한 언어별 라이브러리 존재 



<참조>

  - OAuth v2.0 만능 도구상자 (KTH)

  - OAuth v1.0와 춤을 (NHN)

'Protocols > OAuth' 카테고리의 다른 글

[OAuth] EveryAuth 이용해서 Twitter 인증하기  (0) 2013.10.05
posted by 윤영식
2013. 10. 5. 20:28 Protocols/OAuth

OAuth 트위터에서 Consumer/Acces Key를 생성한 후, Node.js 상에서 EveryAuth를 이용하여 인증방법에 대해서 알아보자 



Twitter 키 생성하기 

  - https://dev.twitter.com/apps/new  에서 생성함

  - 이름, 설명, url -예, http://sv.mobiconsof.co.kr -, 약관체크, CAPCHA등록하고 submit을 하면 키생성 화면이 나온다 

  - 추가로 "access token"을 생성할 수도 있다

     단 여기서 중요한 것은 "Callback URL"을 입력하는 것이다. (sv.mobiconsoft.co.kr은 /etc/hosts파일에 설정한 테스트 도메인)

  - 만들어 놓은 자신의 키들은 https://dev.twitter.com/apps 에서 애플리케이션 별로 확인을 할 수 있다 



Twitter 키 사용하기 

  - Node.js에서 everyauth 모듈을 통하여 사용하는 예를 보자

  - Key 생성시 url로 "http://sv.mobiconsoft.co.kr" 를 입력하였다면 - 각자의 public 또는 test url을 입력하면 된다 - hosts 파일에 등록하고 dig 와 ping 명령으로 확인을 한다 

$ sudo vi /etc/hosts

127.0.0.1    sv.mobiconsoft.co.kr


// ping 성공

$ ping sv.mobiconsoft.co.kr

PING sv.mobiconsoft.co.kr (127.0.0.1): 56 data bytes

64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.044 ms

64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.051 ms

 

  - Express.js, Angular.js 와 Bootstrap을 이용한 코드를 사용할 것이다. 

$ git clone https://github.com/ganarajpr/express-angular.git && cd express-angular

$ 소스 수정하기

  - app.js 안에서 트위터에 대한 consumerKey와 consumerSecret을 입력한다 

everyauth

    .twitter

    .consumerKey('2yQ.....img')

    .consumerSecret('TbhKnP.....fQ1gyvUO4')

    .findOrCreateUser( function (sess, accessToken, accessSecret, twitUser) {

        console.log('twitter User data is', twitUser);

        return usersByTwitId[twitUser.id] || (usersByTwitId[twitUser.id] = addUser('twitter', twitUser));

    })

    .redirectPath('/');

  - Node.js 를 수행한다 

$ sudo node app.js

  - 브라우져에서 호출하기 : 우측 "Login"에서 "Sign in with Twitter" 버튼을 클릭한다 

 - 트위터 승인 화면이 나온다 : "애플리케이션 승인" 버튼을 클릭하면 다시 원래 화면으로 돌아온다 

 - Node.js 콘솔에 뿌려진 사용자 정보를 보자 : 해당 정보를 저장하여 애플리케이션에서 사용을 하면 된다 

$ sudo node app.js

starting step - getRequestToken

...finished step

starting step - storeRequestToken

...finished step

starting step - redirectToProviderAuth

...finished step

starting step - extractTokenAndVerifier

...finished step

starting step - getSession

...finished step

starting step - rememberTokenSecret

...finished step

starting step - getAccessToken

...finished step

starting step - fetchOAuthUser

...finished step

starting step - assignOAuthUserToSession

...finished step

starting step - findOrCreateUser

twitter User data is { id: 48553254,

  id_str: '48553254',

  name: 'Software 행복공동체 키우기',

  screen_name: 'nulpulum',

  location: 'Seoul Korea',

  description: '자건거타기 실용주의프로그래머 에자일정신 글로벌소프트웨어만들기 행복공통체키우기 지식나눔운동',

  url: 'http://t.co/wunTkx6q',

  entities: { url: { urls: [Object] }, description: { urls: [] } },

  protected: false,

  followers_count: 98,

  friends_count: 533,

  listed_count: 0,

  created_at: 'Fri Jun 19 00:44:39 +0000 2009',

  favourites_count: 12,

  utc_offset: 32400,

  time_zone: 'Seoul',

  geo_enabled: true,

  verified: false,

  statuses_count: 506,

  lang: 'ko',

  status:

   { created_at: 'Fri Oct 04 12:15:34 +0000 2013',

     id: 386102292232937500,

     id_str: '386102292232937472',

     text: 'I signed up for Human-Computer Interaction from @ucsandiego on @Coursera! https://t.co/FdQc2h654C #hci',

     source: '<a href="http://twitter.com/tweetbutton" rel="nofollow">Tweet Button</a>',

     truncated: false,

     in_reply_to_status_id: null,

     in_reply_to_status_id_str: null,

     in_reply_to_user_id: null,

     in_reply_to_user_id_str: null,

     in_reply_to_screen_name: null,

     geo: null,

     coordinates: null,

     place: null,

     contributors: null,

     retweet_count: 0,

     favorite_count: 0,

     entities:

      { hashtags: [Object],

        symbols: [],

        urls: [Object],

        user_mentions: [Object] },

     favorited: false,

     retweeted: false,

     possibly_sensitive: false,

     lang: 'en' },

  contributors_enabled: false,

  is_translator: false,

  profile_background_color: '9AE4E8',

  profile_background_image_url: 'http://abs.twimg.com/images/themes/theme16/bg.gif',

  profile_background_image_url_https: 'https://abs.twimg.com/images/themes/theme16/bg.gif',

  profile_background_tile: false,

  profile_image_url: 'http://a0.twimg.com/profile_images/2956822008/b20249749c11917f4ce9e29263ba1b92_normal.jpeg',

  profile_image_url_https: 'https://si0.twimg.com/profile_images/2956822008/b20249749c11917f4ce9e29263ba1b92_normal.jpeg',

  profile_banner_url: 'https://pbs.twimg.com/profile_banners/48553254/1355144673',

  profile_link_color: '0084B4',

  profile_sidebar_border_color: 'BDDCAD',

  profile_sidebar_fill_color: 'DDFFCC',

  profile_text_color: '333333',

  profile_use_background_image: true,

  default_profile: false,

  default_profile_image: false,

  following: false,

  follow_request_sent: false,

  notifications: false }

...finished step

starting step - compileAuth

...finished step

starting step - addToSession

...finished step

starting step - sendResponse

...finished step



<참조> 

  - How to get twitter key

  - Express에서 EveryAuth 사용하기 

  - Facebook에서 EveryAuth 적용하기

'Protocols > OAuth' 카테고리의 다른 글

[OAuth] 인증과 권한 개념잡기  (0) 2013.10.06
posted by 윤영식
2012. 11. 28. 15:17 Protocols

Polyglot 에 기반한 서비스를 만들다 보면 아키텍쳐링을 위하여 Queue 시스템이 필요할 경우가 있다. Message Queue를 위하여 Open Source로 제공되는 구현체들이 존재하기도 한다. 각각에 대한 궁금증을 풀어보자


  • AMQP 무엇인가 : 메세지 통신을 위한 규약 스펙 (참조)
  • 구현체는 무엇들이 있는가 : Rabbit MQ, Apache Qpidetc
  • 어느 때 사용하는가 : 서로 다른 시스템이나 서비스를 업무적으로 엮으고 싶을 경우 (참조)
  • Spring Framework와 잘 어울리는 것은 : Rabbit MQ - spring AMQP 에 포함됨 (참조)

모바일 서비스 구축시 내부 확장과 다양한 언어에 대한 통합을 고려한다면 필수 아이템이 되겠다. 하기 그림은 CloudFoundry에서 제시하는 아키텍쳐이다





'Protocols' 카테고리의 다른 글

MQTT 사용하기 - 1  (1) 2012.09.11
MQTT Push  (0) 2012.09.10
posted by 윤영식
2012. 9. 11. 19:01 Protocols



MQTT Broker인 OSS Mosquitto를 설치하고 Client 프로그램에서 push 내역을 받아서 display 하는 Prototyping을 해보자


▶ MQTT 준비하기

  1. MQTT Broker 설치 :  http://mosquitto.org/download/  개발버전은 윈도우 binary  설치, 운영버전은 Linux binary 설치 
    • 윈도우 버전으로 설치하면 service로 등록된다 (Mosquitto Broker)
    • Linux는 mosquitto 계정을 만들고 root에서 설치를 한다 (자동으로 mosquitto 계정을 찾아 설치해 준다)
  2. mosquitto 운영 : 모스퀴토 브로커(서버)를 기동하는 방법을 알아보자
    • http://mosquitto.org/man/mosquitto-8.html  모스퀴토 서버의 기동 방법과 시스템 환경변수의 종류 설명
    • mosquitto 의 환경변수는 $SYS topic등록으로 client가 받아 볼 수 있다
    • + # 기호를 통해 topic등록 가능
    • Bridge 설정을 통해서 multi broker 설정이 가능 (mosquitto.conf)
    • 메세지에 대한 file writing을 할 수 있음 
    • 특정 host, ip 접근 제어가 가능 
    • https://launchpad.net/mosquitto  버그 레포팅 사이트
  3. MQTT client 라이브로리 선택

▶ MQTT 설치하기 

  1. 아키텍쳐 설명 
    1. 네이버 자료 : http://helloworld.naver.com/helloworld/1846
    2. 성능 : ftp://public.dhe.ibm.com/software/kr/ik2012/mqtt.pdf
  2. 설치 : mosquitto broker 설치 
    1. 설치하기 : http://ceit.uq.edu.au/content/installing-mosquitto-under-centos
    2. /etc/sudoers 설정 : sudo su 명령 실행이 안될 경우 셋팅한다 
    3. [root@www etc]# cat sudoers | grep mosquitto
      mosquitto ALL=(ALL) ALL

    4. bin :  /usr/sbin/mosquitto
  3. 기동 : mosquitto 계정 접속 

           > sudo su

           > ./startMqtt.sh

  4. 결과 확인 

[root@www mosquitto]# netstat -na | grep 1883
tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN
tcp 0 0 :::1883 :::* LISTEN
[root@www mosquitto]# ps -ef | grep mosquitto
root 2641 2467 0 14:43 pts/0 00:00:00 su - mosquitto
504 2676 1 0 14:44 pts/0 00:00:00 /usr/sbin/mosquitto -d -c /etc/mosquitto/mosquitto.conf
root 2680 2664 0 14:44 pts/0 00:00:00 grep mosquitto


   5. 환경설정 

  • /etc/mosquitto/mosquitto.conf 
  • wildcard : +  #

   6. Client

 

'Protocols' 카테고리의 다른 글

Advanced Message Queueing Protocol (AMQP) 란 무엇인가  (0) 2012.11.28
MQTT Push  (0) 2012.09.10
posted by 윤영식
2012. 9. 10. 13:37 Protocols



모바일 폰에서 Push 통신을 하기 위한 방법에는 C2DM, MQTT, Node.js등이 존재한다. 여기서 MQTT를 예전 프로젝트에서 진행해 보았는데, 참조하자. 시간이 허락된다면 C버전으로 되어 있는 MQTT Broker 서버를 Java 버전으로 개발해서 OSS(Open Source Software)로 공개하고 싶다. 자 그럼 MQTT의 세상속으로 빠져보아요~~~


MQ Telemetry Transport

MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.



MQTT에 대해 이해하기 



MQTT 소프트웨어 참조 방법


MQTT Broker Java 버전을 만들기 위해한 스터디


MQTT Prototyping 해보기 

'Protocols' 카테고리의 다른 글

Advanced Message Queueing Protocol (AMQP) 란 무엇인가  (0) 2012.11.28
MQTT 사용하기 - 1  (1) 2012.09.11
posted by 윤영식
prev 1 next