Skip to content

Commit 35a55c2

Browse files
authored
Remove OAuth token exchange (#161)
1 parent 6848725 commit 35a55c2

File tree

2 files changed

+1
-45
lines changed

2 files changed

+1
-45
lines changed

src/hex_api_oauth.erl

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
device_authorization/3,
66
device_authorization/4,
77
poll_device_token/3,
8-
exchange_token/4,
98
refresh_token/3,
109
revoke_token/3
1110
]).
@@ -90,34 +89,6 @@ poll_device_token(Config, ClientId, DeviceCode) ->
9089
},
9190
hex_api:post(Config, Path, Params).
9291

93-
%% @doc
94-
%% Exchanges a token for a new token with different scopes using RFC 8693 token exchange.
95-
%%
96-
%% Examples:
97-
%%
98-
%% ```
99-
%% 1> Config = hex_core:default_config().
100-
%% 2> hex_api_oauth:exchange_token(Config, <<"cli">>, SubjectToken, <<"api:write">>).
101-
%% {ok, {200, _, #{
102-
%% <<"access_token">> => <<"...">>,
103-
%% <<"refresh_token">> => <<"...">>,
104-
%% <<"token_type">> => <<"Bearer">>,
105-
%% <<"expires_in">> => 3600
106-
%% }}}
107-
%% '''
108-
%% @end
109-
-spec exchange_token(hex_core:config(), binary(), binary(), binary()) -> hex_api:response().
110-
exchange_token(Config, ClientId, SubjectToken, Scope) ->
111-
Path = <<"oauth/token">>,
112-
Params = #{
113-
<<"grant_type">> => <<"urn:ietf:params:oauth:grant-type:token-exchange">>,
114-
<<"subject_token">> => SubjectToken,
115-
<<"subject_token_type">> => <<"urn:ietf:params:oauth:token-type:access_token">>,
116-
<<"client_id">> => ClientId,
117-
<<"scope">> => Scope
118-
},
119-
hex_api:post(Config, Path, Params).
120-
12192
%% @doc
12293
%% Refreshes an access token using a refresh token.
12394
%%

test/hex_api_SUITE.erl

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ suite() ->
2020

2121
all() ->
2222
[package_test, release_test, replace_test, user_test, owner_test, keys_test, auth_test, short_url_test,
23-
oauth_device_flow_test, oauth_token_exchange_test, oauth_refresh_token_test, oauth_revoke_test,
23+
oauth_device_flow_test, oauth_refresh_token_test, oauth_revoke_test,
2424
publish_with_expect_header_test, publish_without_expect_header_test].
2525

2626
package_test(_Config) ->
@@ -132,21 +132,6 @@ oauth_device_flow_test(_Config) ->
132132
#{<<"error">> := <<"authorization_pending">>} = PollResponse,
133133
ok.
134134

135-
oauth_token_exchange_test(_Config) ->
136-
% Test token exchange
137-
ClientId = <<"cli">>,
138-
SubjectToken = <<"test_api_key">>,
139-
Scope = <<"api:read">>,
140-
{ok, {200, _, TokenResponse}} = hex_api_oauth:exchange_token(?CONFIG, ClientId, SubjectToken, Scope),
141-
#{
142-
<<"access_token">> := AccessToken,
143-
<<"token_type">> := <<"Bearer">>,
144-
<<"expires_in">> := ExpiresIn
145-
} = TokenResponse,
146-
?assert(is_binary(AccessToken)),
147-
?assert(is_integer(ExpiresIn)),
148-
ok.
149-
150135
oauth_refresh_token_test(_Config) ->
151136
% Test token refresh
152137
ClientId = <<"cli">>,

0 commit comments

Comments
 (0)