|
1 | | -%% Vendored from hex_core v0.11.0 (75e889f), do not edit manually |
| 1 | +%% Vendored from hex_core v0.11.0 (94a912d), do not edit manually |
2 | 2 |
|
3 | 3 | %% @doc |
4 | 4 | %% Hex HTTP API - OAuth. |
5 | 5 | -module(mix_hex_api_oauth). |
6 | 6 | -export([ |
7 | 7 | device_authorization/3, |
| 8 | + device_authorization/4, |
8 | 9 | poll_device_token/3, |
9 | 10 | exchange_token/4, |
10 | 11 | refresh_token/3, |
|
33 | 34 | %% @end |
34 | 35 | -spec device_authorization(mix_hex_core:config(), binary(), binary()) -> mix_hex_api:response(). |
35 | 36 | device_authorization(Config, ClientId, Scope) -> |
| 37 | + device_authorization(Config, ClientId, Scope, []). |
| 38 | + |
| 39 | +%% @doc |
| 40 | +%% Initiates the OAuth device authorization flow with optional parameters. |
| 41 | +%% |
| 42 | +%% Options: |
| 43 | +%% * name - A name to identify the token (e.g., hostname of the device) |
| 44 | +%% |
| 45 | +%% Examples: |
| 46 | +%% |
| 47 | +%% ``` |
| 48 | +%% 1> Config = mix_hex_core:default_config(). |
| 49 | +%% 2> mix_hex_api_oauth:device_authorization(Config, <<"cli">>, <<"api:write">>, [{name, <<"MyMachine">>}]). |
| 50 | +%% ''' |
| 51 | +%% @end |
| 52 | +-spec device_authorization(mix_hex_core:config(), binary(), binary(), proplists:proplist()) -> mix_hex_api:response(). |
| 53 | +device_authorization(Config, ClientId, Scope, Opts) -> |
36 | 54 | Path = <<"oauth/device_authorization">>, |
37 | | - Params = #{ |
| 55 | + Params0 = #{ |
38 | 56 | <<"client_id">> => ClientId, |
39 | 57 | <<"scope">> => Scope |
40 | 58 | }, |
| 59 | + Params = case proplists:get_value(name, Opts) of |
| 60 | + undefined -> Params0; |
| 61 | + Name -> Params0#{<<"name">> => Name} |
| 62 | + end, |
41 | 63 | mix_hex_api:post(Config, Path, Params). |
42 | 64 |
|
43 | 65 | %% @doc |
|
0 commit comments