Skip to content

Commit

Permalink
Merge pull request #58 from wingyplus/line-login
Browse files Browse the repository at this point in the history
Add LINE Login OpenID Connect Strategy
  • Loading branch information
danschultzer authored Oct 18, 2020
2 parents d5090b7 + ea966d4 commit 18b6715
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* `Assent.Strategy.OIDC.validate_id_token/2` has a bug fixed where `alg` was not validated correctly
* `Assent.Strategy.OIDC` now has an `:id_token_signed_response_alg` configuration option
* `Assent.Strategy.LINE` added

## v0.1.14 (2020-10-11)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Multi-provider authentication framework.
* Slack - `Assent.Strategy.Slack`
* Twitter - `Assent.Strategy.Twitter`
* VK - `Assent.Strategy.VK`
* LINE Login - `Assent.Strategy.LINE`

## Installation

Expand Down
21 changes: 21 additions & 0 deletions lib/assent/strategies/line.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Assent.Strategy.LINE do
@moduledoc """
LINE Login OpenID Connect Strategy.
See `Assent.Strategy.OIDC` for more.
"""

use Assent.Strategy.OIDC.Base

@impl true
def default_config(_config) do
[
site: "https://access.line.me",
authorization_params: [scope: "email profile", response_type: "code"],
id_token_signed_response_alg: "HS256"
]
end

@impl true
def normalize(_config, user), do: {:ok, user}
end
44 changes: 44 additions & 0 deletions test/assent/strategies/line_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
defmodule Assent.Strategy.LINETest do
use Assent.Test.OIDCTestCase

alias Assent.Strategy.LINE

# From https://developers.line.biz/en/docs/line-login/integrate-line-login/#verify-id-token
@id_token elem(Assent.Strategy.sign_jwt(
%{
"iss" => "https://access.line.me",
"sub" => "U1234567890abcdef1234567890abcdef ",
"aud" => "1234567890",
"exp" => :os.system_time(:second) + 60,
"iat" => :os.system_time(:second),
"nonce" => "0987654asdf",
"amr" => ["pwd"],
"name" => "Taro Line",
"picture" => "https://sample_line.me/aBcdefg123456"
},
"HS256",
"secret",
[]), 1)
@user %{
"name" => "Taro Line",
"picture" => "https://sample_line.me/aBcdefg123456",
"sub" => "U1234567890abcdef1234567890abcdef "
}

test "authorize_url/2", %{config: config} do
assert {:ok, %{url: url}} = LINE.authorize_url(config)
assert url =~ "scope=openid+email+profile"
assert url =~ "response_type=code"
end

test "callback/2", %{config: config, callback_params: params, bypass: bypass} do
openid_config = Map.merge(config[:openid_configuration], %{"issuer" => "https://access.line.me"})
session_params = Map.put(config[:session_params], :nonce, "0987654asdf")
config = Keyword.merge(config, openid_configuration: openid_config, client_id: "1234567890", session_params: session_params)

expect_oidc_access_token_request(bypass, id_token: @id_token)

assert {:ok, %{user: user}} = LINE.callback(config, params)
assert user == @user
end
end

0 comments on commit 18b6715

Please sign in to comment.