Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/oidcc_token.erl
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ extract_scope(TokenMap, Opts) ->
case maps:get(<<"scope">>, TokenMap, oidcc_scope:scopes_to_bin(Scopes)) of
ScopeBinary when is_binary(ScopeBinary) ->
{ok, oidcc_scope:parse(ScopeBinary)};
%% Some providers (e.g. Apple and Twitch) are setting the scope value
%% as list of string. This extends compatibility for those.
ScopeList when is_list(ScopeList) ->
{ok, ScopeList};
ScopeOther ->
{error, {invalid_property, {scope, ScopeOther}}}
end.
Expand Down
116 changes: 59 additions & 57 deletions test/oidcc/token_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,65 +50,67 @@ defmodule Oidcc.TokenTest do
end

describe inspect(&Token.retrieve/3) do
test_with_mock "works", %{}, :oidcc_http_util, [],
request: fn :post,
{"https://my.provider/token", _headers, ~c"application/x-www-form-urlencoded",
_body},
_telemetry_opts,
_http_opts ->
{_jws, token} =
@example_jwks
|> JOSE.JWT.sign(
%{"alg" => "RS256"},
JOSE.JWT.from(%{
"iss" => "https://my.provider",
"sub" => "sub",
"aud" => "client_id",
"iat" => :erlang.system_time(:second),
"exp" => :erlang.system_time(:second) + 10
})
)
|> JOSE.JWS.compact()
for scope <- ["profile openid", ["profile", "openid"]] do
test_with_mock "works with scope: #{inspect(scope)}", %{}, :oidcc_http_util, [],
request: fn :post,
{"https://my.provider/token", _headers, ~c"application/x-www-form-urlencoded",
_body},
_telemetry_opts,
_http_opts ->
{_jws, token} =
@example_jwks
|> JOSE.JWT.sign(
%{"alg" => "RS256"},
JOSE.JWT.from(%{
"iss" => "https://my.provider",
"sub" => "sub",
"aud" => "client_id",
"iat" => :erlang.system_time(:second),
"exp" => :erlang.system_time(:second) + 10
})
)
|> JOSE.JWS.compact()

{:ok,
{{:json,
%{
"access_token" => "access_token",
"token_type" => "Bearer",
"id_token" => token,
"scope" => "profile openid",
"refresh_token" => "refresh_token"
}}, []}}
end do
client_context =
ClientContext.from_manual(
@example_metadata,
@example_jwks,
"client_id",
"client_secret"
)
{:ok,
{{:json,
%{
"access_token" => "access_token",
"token_type" => "Bearer",
"id_token" => token,
"scope" => unquote(scope),
"refresh_token" => "refresh_token"
}}, []}}
end do
client_context =
ClientContext.from_manual(
@example_metadata,
@example_jwks,
"client_id",
"client_secret"
)

assert {:ok,
%Token{
id: %Token.Id{
token: _token,
claims: %{
"aud" => "client_id",
"exp" => _exp,
"iat" => _iat,
"iss" => "https://my.provider",
"sub" => "sub"
}
},
access: %Token.Access{token: "access_token", expires: :undefined},
refresh: %Token.Refresh{token: "refresh_token"},
scope: ["profile", "openid"]
}} =
Token.retrieve(
"auth_code",
client_context,
%{redirect_uri: "https://my.server/return"}
)
assert {:ok,
%Token{
id: %Token.Id{
token: _token,
claims: %{
"aud" => "client_id",
"exp" => _exp,
"iat" => _iat,
"iss" => "https://my.provider",
"sub" => "sub"
}
},
access: %Token.Access{token: "access_token", expires: :undefined},
refresh: %Token.Refresh{token: "refresh_token"},
scope: ["profile", "openid"]
}} =
Token.retrieve(
"auth_code",
client_context,
%{redirect_uri: "https://my.server/return"}
)
end
end
end

Expand Down
Loading