Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Materia.pdf

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

 Materia.pdf

Avatar for TakutoYoshimura

TakutoYoshimura

January 25, 2019
Tweet

More Decks by TakutoYoshimura

Other Decks in Technology

Transcript

  1. Materia とは 弊社カラビナテクノロジーで開発中の Elixir/Phoenix 製サービスバックエンドライブラリ SPA(Single Page Application) での開発を想定した バックエンドAPI

    を提供 サービスとして特色のないユーザー管理や認証と いった部分のバックエンド機能を個別開発せず に、本来実装したいサービスの特色となる機能の 開発に注力 Qiita 記事: Web サービスバックエンドライブラリー Materia
  2. 導入のステップ |> deps.get |> config 設定 |> migration ファイル生成 |>

    router.ex で必要な認証機構とAPI を定義 materia README
  3. deps.get mix.exs defp deps do [ {:phoenix, "~> 1.3.2"}, ~

    中略 ~ {:cowboy, "~> 1.0"}, {:materia, "~> 0.1.2"} # add here ] > mix deps.get
  4. con g 設定 jwt 認証(guardian) の設定 Repo の設定 参考 materia

    README Materia を導入してログイン認証してみる
  5. migration ファイル作成 > mix guardian.db.gen.migration > mix materia.gen.migration > mix

    ecto.create > mix ecto.migrate > mix run priv/repo/seeds.exs
  6. ルーティング設定 pipeline で認証ロジックの設定 pipeline :user_auth do plug Materia.UserAuthPipeline end pipe_through

    でAPI 毎にパイプラインを指定 scope "/api", MateriaWeb do pipe_through [ :api, :user_auth] get "/user", UserController, :show_me post "/grant", GrantController, :get_by_role end
  7. ログインAPI レスポンス HTTP/1.1 201 Created server: Cowboy date: Fri, 14

    Dec 2018 08:16:32 GMT content-length: 740 content-type: application/json; charset=utf-8 cache-control: max-age=0, private, must-revalidate { "refresh_token": "hogehoge", "id": 1, "access_token": "fugafuga" }