Single sign-on inter Rails applications


Chikahiro Tokoro

* Who am i?

Just Moved from Japan to Berlin!
Freelancer
Rubyist


http://ctokoro.me/

* Background



The client wanted to make building a new sister product 

with

 signing on/up by existing product



At first they wanted to launch it quickly

and gather users.

there were very less time for implement it,

they choose shared existing Database.

like this architecture



* Issue

Tables only for new App B also existing in one Database

It was Rails application, 
managing schema  default migration 
on existing  App A even for new App B

* ISSUE

Tables only for new App B also existing in one Database

It was Rails application, 
managing schema  default migration 
on existing  App A even for new App B

It made high complexity for development process,
The client doesn't want create a new tables any more.
its really ridiculous!

* Solution

Change architecture!

Demand:

* User authentication
* Sharing data of common tables/columns 
* Very quick to launch!!

 we made 3 plans of architecture

PLAN 1:  API for User

    








     GOOD:  Less man-hours for implementation
     BAD:
              * New application B still depends on exiting Database
     * low performance..

Plan 2:  OAuth


     GOOD:  Loosey-coupled
     BAD: 
            * estimated a lot of man-hours
        * need something more for sharing data of common tables/columns
PLAN3: Cutting out and mount as Rails Engine


           GOOD:  looks satisfy all demands
           BAD:  how to implement? 
                ( it needs to deal with multiple database in app )

補足: Rails Engineとは?


Railsアプリケーションを再利用可能にするように、

本体にマウント可能にする


↑↓

プラグイン、gem


・Rackミドルウェアである

・routes, task等を独自に記述できる

などなど






Let's make a prototype for estimating difficulty!

* PrototypiPE


* PLAN1: API for User
No, it looks bad architecture,,

* PLAN 2:  OAuth

gem 'doorkeeper'


* PLAN 3: Rails Engine

 ActiveRecord establish_connection

https://github.com/rails/rails/pull/24965


Estimated man-hours were similar with PLAN 2 and 3


PLAN2:  OAuth

no future plan of publishing externally, it's overspec


PLAN3:   Rails Engine

 satisfy all demands! and challenging 🙂


We choose 

PLAN 3: Rails Engine

* Code




Thank you for listening 🙂

And I'm looking for job!

Feel free to contact me!

Chikahiro Tokoro 
http://ctokoro.me/
Made with Slides.com