Skip to content

Commit

Permalink
Merge branch 'master' into fix-pkce-verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
bwegh authored Jul 3, 2018
2 parents b0d9372 + 09061ad commit f0a344b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/oidcc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-export([add_openid_provider/2]).
-export([add_openid_provider/3]).
-export([find_openid_provider/1]).
-export([find_all_openid_provider/1]).
-export([get_openid_provider_info/1]).
-export([get_openid_provider_list/0]).
-export([create_redirect_url/1]).
Expand Down Expand Up @@ -56,6 +57,11 @@ add_openid_provider(IssuerOrConfigEP, LocalEndpoint, AdditionalConfig) ->
find_openid_provider(Issuer) ->
oidcc_openid_provider_mgr:find_openid_provider(Issuer).

-spec find_all_openid_provider(Issuer::binary()) -> {ok, [pid()]}
| {error, not_found}.
find_all_openid_provider(Issuer) ->
oidcc_openid_provider_mgr:find_all_openid_provider(Issuer).

%% @doc
%% get information from a given OpenId Connect Provider
%%
Expand Down
29 changes: 21 additions & 8 deletions src/oidcc_openid_provider_mgr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
-export([add_openid_provider/1]).
-export([get_openid_provider/1]).
-export([find_openid_provider/1]).
-export([find_all_openid_provider/1]).
-export([get_openid_provider_list/0]).


Expand Down Expand Up @@ -52,13 +53,18 @@ get_openid_provider_list() ->
-spec find_openid_provider(Issuer::binary()) -> {ok, pid()}
| {error, not_found}.
find_openid_provider(Issuer) ->
find_provider(Issuer).
find_provider(Issuer, false).

-spec find_all_openid_provider(Issuer::binary()) -> {ok, [pid()]}
| {error, not_found}.
find_all_openid_provider(Issuer) ->
find_provider(Issuer, true).

%% gen_server.

init([]) ->
ProvEts = ets:new(oidcc_ets_provider, [set, protected, named_table]),
IssEts = ets:new(oidcc_ets_issuer, [set, protected, named_table]),
IssEts = ets:new(oidcc_ets_issuer, [bag, protected, named_table]),
MonEts = ets:new(oidcc_ets_monitor, [set, protected]),
{ok, #state{ets_prov=ProvEts, ets_iss=IssEts, ets_mon = MonEts}}.

Expand All @@ -75,15 +81,15 @@ handle_cast(_Msg, State) ->
{noreply, State}.


handle_info({'DOWN', MRef, process, _Object, _Info},
handle_info({'DOWN', MRef, process, Pid, _Info},
#state{ets_mon=MonEts, ets_prov=ProvEts, ets_iss=IssEts} = State) ->
case ets:lookup(MonEts, MRef) of
[{MRef, Id, Issuer}] ->
[Issuer1, Issuer2] = to_issuer(Issuer),
true = ets:delete(MonEts, MRef),
true = ets:delete(ProvEts, Id),
true = ets:delete(IssEts, Issuer1),
true = ets:delete(IssEts, Issuer2),
true = ets:delete_object(IssEts, {Issuer1, Pid}),
true = ets:delete_object(IssEts, {Issuer2, Pid}),
ok;
_ -> ok
end,
Expand Down Expand Up @@ -128,11 +134,18 @@ get_provider(Id) ->
_ -> {error, not_found}
end.

find_provider(Issuer) ->
find_provider(Issuer, All) ->
Ets = oidcc_ets_issuer,
case ets:lookup(Ets, Issuer) of
[{Issuer, Pid}] ->
case {ets:lookup(Ets, Issuer), All} of
{[{Issuer, Pid}], false} ->
{ok, Pid};
{[], _} ->
{error, not_found};
{List, true} when is_list(List) ->
ToPid = fun({_, Pid}, Pids) ->
[Pid | Pids]
end,
{ok, lists:foldl(ToPid, [], List)};
_ ->
{error, not_found}
end.
Expand Down

0 comments on commit f0a344b

Please sign in to comment.