Advertisement
vheathen

Untitled

May 20th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 2.19 KB | None | 0 0
  1. iex(1)> alias App.{Repo, Device, DeviceRegistration.Monitor}
  2. [nil, nil, nil]
  3. iex(2)> device = Repo.get_by(Device, id: "db749ee8-1e9f-11e6-9d47-4b5e65de4b92")
  4. [debug] QUERY OK db=2.9ms decode=0.2ms queue=0.2ms
  5. SELECT d0."id", d0."is_enabled", d0."user_id", d0."inserted_at", d0."updated_at" FROM "devices" AS d0 WHERE (d0."id" = $1) [<<219, 116, 158, 232, 30, 159, 17, 230, 157, 71, 75, 94, 101, 222, 75, 146>>]
  6. %App.Device{__meta__: #Ecto.Schema.Metadata<:loaded>,
  7.  id: "db749ee8-1e9f-11e6-9d47-4b5e65de4b92",
  8.  inserted_at: #Ecto.DateTime<2016-05-20 15:31:01>, is_enabled: true,
  9.  updated_at: #Ecto.DateTime<2016-05-20 15:31:01>,
  10.  user: #Ecto.Association.NotLoaded<association :user is not loaded>,
  11.  user_id: nil}
  12. iex(3)> ttl = Application.get_env(:app, :reg_ttl)
  13. {30, :minutes}
  14. iex(4)> claims = Guardian.Claims.app_claims |> Guardian.Claims.ttl(ttl)
  15. %{"exp" => 1463768778, "iat" => 1463766978, "iss" => "StreamTo.TV",
  16.   "jti" => "7dc915a5-ff0b-4d41-bc1b-b19804550897"}
  17. iex(5)> exp_at = claims["exp"]
  18. 1463768778
  19. iex(6)> %{code: code, exp: old_exp_at} = Monitor.device_added(device.id, exp_at)
  20. %{code: "LCBZH6WW", exp: 1463768716}
  21. iex(7)> ttl = {old_exp_at - :os.system_time(:seconds) - 1, :seconds}
  22. {1709, :seconds}
  23. iex(8)> claims = Guardian.Claims.app_claims |> Guardian.Claims.ttl(ttl)
  24. %{"exp" => 1463768725, "iat" => 1463767016, "iss" => "StreamTo.TV",
  25.   "jti" => "294a5c14-f5e4-4b57-9f30-e6551825ccaf"}
  26. iex(9)> {:ok, token, _full_claims} = Guardian.encode_and_sign(device, :token, claims)
  27. {:ok,
  28.  "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJEZXZpY2U6ZGI3NDllZTgtMWU5Zi0xMWU2LTlkNDctNGI1ZTY1ZGU0YjkyIiwiZXhwIjoxNDY0MDI2MjE2LCJpYXQiOjE0NjM3NjcwMTYsImlzcyI6IlN0cmVhbVRvLlRWIiwianRpIjoiMjk0YTVjMTQtZjVlNC00YjU3LTlmMzAtZTY1NTE4MjVjY2FmIiwicGVtIjp7fSwic3ViIjoiRGV2aWNlOmRiNzQ5ZWU4LTFlOWYtMTFlNi05ZDQ3LTRiNWU2NWRlNGI5MiIsInR5cCI6InRva2VuIn0.Xb884XjrQ8bOJUIQw8_UBQ2Me_flTKQtXnpmp2oio4F3BSpMUkwkJCOXhcRCyer5xcJyYAU6vbGQDRy2vDZv3w",
  29.  %{"aud" => "Device:db749ee8-1e9f-11e6-9d47-4b5e65de4b92", "exp" => 1464026216,
  30.    "iat" => 1463767016, "iss" => "StreamTo.TV",
  31.    "jti" => "294a5c14-f5e4-4b57-9f30-e6551825ccaf", "pem" => %{},
  32.    "sub" => "Device:db749ee8-1e9f-11e6-9d47-4b5e65de4b92", "typ" => "token"}}
  33. iex(10)>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement