Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- iex(1)> alias App.{Repo, Device, DeviceRegistration.Monitor}
- [nil, nil, nil]
- iex(2)> device = Repo.get_by(Device, id: "db749ee8-1e9f-11e6-9d47-4b5e65de4b92")
- [debug] QUERY OK db=2.9ms decode=0.2ms queue=0.2ms
- 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>>]
- %App.Device{__meta__: #Ecto.Schema.Metadata<:loaded>,
- id: "db749ee8-1e9f-11e6-9d47-4b5e65de4b92",
- inserted_at: #Ecto.DateTime<2016-05-20 15:31:01>, is_enabled: true,
- updated_at: #Ecto.DateTime<2016-05-20 15:31:01>,
- user: #Ecto.Association.NotLoaded<association :user is not loaded>,
- user_id: nil}
- iex(3)> ttl = Application.get_env(:app, :reg_ttl)
- {30, :minutes}
- iex(4)> claims = Guardian.Claims.app_claims |> Guardian.Claims.ttl(ttl)
- %{"exp" => 1463768778, "iat" => 1463766978, "iss" => "StreamTo.TV",
- "jti" => "7dc915a5-ff0b-4d41-bc1b-b19804550897"}
- iex(5)> exp_at = claims["exp"]
- 1463768778
- iex(6)> %{code: code, exp: old_exp_at} = Monitor.device_added(device.id, exp_at)
- %{code: "LCBZH6WW", exp: 1463768716}
- iex(7)> ttl = {old_exp_at - :os.system_time(:seconds) - 1, :seconds}
- {1709, :seconds}
- iex(8)> claims = Guardian.Claims.app_claims |> Guardian.Claims.ttl(ttl)
- %{"exp" => 1463768725, "iat" => 1463767016, "iss" => "StreamTo.TV",
- "jti" => "294a5c14-f5e4-4b57-9f30-e6551825ccaf"}
- iex(9)> {:ok, token, _full_claims} = Guardian.encode_and_sign(device, :token, claims)
- {:ok,
- "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJEZXZpY2U6ZGI3NDllZTgtMWU5Zi0xMWU2LTlkNDctNGI1ZTY1ZGU0YjkyIiwiZXhwIjoxNDY0MDI2MjE2LCJpYXQiOjE0NjM3NjcwMTYsImlzcyI6IlN0cmVhbVRvLlRWIiwianRpIjoiMjk0YTVjMTQtZjVlNC00YjU3LTlmMzAtZTY1NTE4MjVjY2FmIiwicGVtIjp7fSwic3ViIjoiRGV2aWNlOmRiNzQ5ZWU4LTFlOWYtMTFlNi05ZDQ3LTRiNWU2NWRlNGI5MiIsInR5cCI6InRva2VuIn0.Xb884XjrQ8bOJUIQw8_UBQ2Me_flTKQtXnpmp2oio4F3BSpMUkwkJCOXhcRCyer5xcJyYAU6vbGQDRy2vDZv3w",
- %{"aud" => "Device:db749ee8-1e9f-11e6-9d47-4b5e65de4b92", "exp" => 1464026216,
- "iat" => 1463767016, "iss" => "StreamTo.TV",
- "jti" => "294a5c14-f5e4-4b57-9f30-e6551825ccaf", "pem" => %{},
- "sub" => "Device:db749ee8-1e9f-11e6-9d47-4b5e65de4b92", "typ" => "token"}}
- iex(10)>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement