forked from 2600hz/kazoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more crossbar bindings (2600hz#6277)
add support for creating Bearer Kazoo Tokens * Sometimes JWT Tokens can be excessive in size. For long running integrations, we need to provide Bearer Tokens that can be scoped and invalidated at any time. * this is not a replacement for user auth * modules should be allowed to fetch the request data to avoid normalizing the payload. * it may confuse log readers when there are UTF characters in the payload * some SSO integrations require the username as-is this allows to skip username normalization by setting 'normalize_username' to false in crossbar context
- Loading branch information
1 parent
6d763df
commit 6a73856
Showing
10 changed files
with
97 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
%%%----------------------------------------------------------------------------- | ||
%%% @copyright (C) 2012-2020, 2600Hz | ||
%%% @doc | ||
%%% This Source Code Form is subject to the terms of the Mozilla Public | ||
%%% License, v. 2.0. If a copy of the MPL was not distributed with this | ||
%%% file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
%%% | ||
%%% @end | ||
%%%----------------------------------------------------------------------------- | ||
-module(kz_auth_bearer). | ||
|
||
%%============================================================================== | ||
%% API functions | ||
%%============================================================================== | ||
|
||
-export([create/1 | ||
,fetch/1 | ||
]). | ||
|
||
-include("kazoo_auth.hrl"). | ||
|
||
-spec create(kz_term:proplist()) -> | ||
{'ok', kz_term:ne_binary()} | | ||
{'error', 'algorithm_not_supported'} | | ||
kz_datamgr:data_error(). | ||
create(Claims) -> | ||
case kz_auth:create_token(Claims) of | ||
{'ok', Token} -> save_token(Token); | ||
Else -> Else | ||
end. | ||
|
||
-spec fetch(kz_term:ne_binary()) -> kz_term:api_ne_binary(). | ||
fetch(Bearer) -> | ||
case kz_datamgr:open_cache_doc(?KZ_AUTH_DB, Bearer) of | ||
{'ok', JObj} -> kz_json:get_ne_binary_value(<<"Token">>, JObj); | ||
Else -> Else | ||
end. | ||
|
||
-spec save_token(binary()) -> | ||
{'ok', kz_term:ne_binary()} | | ||
kz_datamgr:data_error(). | ||
save_token(Token) -> | ||
JObj = kz_json:from_list([{<<"Token">>, Token}]), | ||
Doc = kz_doc:update_pvt_parameters(JObj, ?KZ_AUTH_DB, [{'type', <<"bearer-token">>}]), | ||
case kz_datamgr:save_doc(?KZ_AUTH_DB, Doc) of | ||
{'ok', Created} -> {'ok', kz_doc:id(Created)}; | ||
Else -> Else | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters