tangled
alpha
login
or
join now
lekkice.moe
/
atex
forked from
comet.sh/atex
0
fork
atom
A set of utilities for working with the AT Protocol in Elixir.
0
fork
atom
overview
issues
pulls
1
pipelines
fix: use lazy evaluation for fetching Oauth config
lekkice.moe
1 month ago
be893ce7
ed865a6b
+29
-35
1 changed file
expand all
collapse all
unified
split
lib
atex
oauth.ex
+29
-35
lib/atex/oauth.ex
···
80
80
@spec create_client_metadata(list(create_client_metadata_option())) :: map()
81
81
def create_client_metadata(opts \\ []) do
82
82
opts =
83
83
-
Keyword.validate!(opts,
84
84
-
key: Config.get_key(),
85
85
-
client_id: Config.client_id(),
86
86
-
redirect_uri: Config.redirect_uri(),
87
87
-
extra_redirect_uris: Config.extra_redirect_uris(),
88
88
-
scopes: Config.scopes()
83
83
+
Keyword.validate!(
84
84
+
opts,
85
85
+
[:key, :client_id, :redirect_uri, :extra_redirect_uris, :scopes]
89
86
)
90
87
91
91
-
key = Keyword.get(opts, :key)
92
92
-
client_id = Keyword.get(opts, :client_id)
93
93
-
redirect_uri = Keyword.get(opts, :redirect_uri)
94
94
-
extra_redirect_uris = Keyword.get(opts, :extra_redirect_uris)
95
95
-
scopes = Keyword.get(opts, :scopes)
88
88
+
key = Keyword.get_lazy(opts, :key, &Config.get_key/0)
89
89
+
client_id = Keyword.get_lazy(opts, :client_id, &Config.client_id/0)
90
90
+
redirect_uri = Keyword.get_lazy(opts, :redirect_uri, &Config.redirect_uri/0)
91
91
+
92
92
+
extra_redirect_uris =
93
93
+
Keyword.get_lazy(opts, :extra_redirect_uris, &Config.extra_redirect_uris/0)
94
94
+
95
95
+
scopes = Keyword.get_lazy(opts, :scopes, &Config.scopes/0)
96
96
97
97
{_, jwk} = key |> JOSE.JWK.to_public_map()
98
98
jwk = Map.merge(jwk, %{use: "sig", kid: key.fields["kid"]})
···
179
179
opts \\ []
180
180
) do
181
181
opts =
182
182
-
Keyword.validate!(opts,
183
183
-
key: Config.get_key(),
184
184
-
client_id: Config.client_id(),
185
185
-
redirect_uri: Config.redirect_uri(),
186
186
-
scopes: Config.scopes()
182
182
+
Keyword.validate!(
183
183
+
opts,
184
184
+
[:key, :client_id, :redirect_uri, :scopes]
187
185
)
188
186
189
189
-
key = Keyword.get(opts, :key)
190
190
-
client_id = Keyword.get(opts, :client_id)
191
191
-
redirect_uri = Keyword.get(opts, :redirect_uri)
192
192
-
scopes = Keyword.get(opts, :scopes)
187
187
+
key = Keyword.get_lazy(opts, :key, &Config.get_key/0)
188
188
+
client_id = Keyword.get_lazy(opts, :client_id, &Config.client_id/0)
189
189
+
redirect_uri = Keyword.get_lazy(opts, :redirect_uri, &Config.redirect_uri/0)
190
190
+
scopes = Keyword.get_lazy(opts, :scopes, &Config.scopes/0)
193
191
194
192
code_challenge = :crypto.hash(:sha256, code_verifier) |> Base.url_encode64(padding: false)
195
193
···
260
258
opts \\ []
261
259
) do
262
260
opts =
263
263
-
Keyword.validate!(opts,
264
264
-
key: get_key(),
265
265
-
client_id: Config.client_id(),
266
266
-
redirect_uri: Config.redirect_uri(),
267
267
-
scopes: Config.scopes()
261
261
+
Keyword.validate!(
262
262
+
opts,
263
263
+
[:key, :client_id, :redirect_uri, :scopes]
268
264
)
269
265
270
270
-
key = Keyword.get(opts, :key)
271
271
-
client_id = Keyword.get(opts, :client_id)
272
272
-
redirect_uri = Keyword.get(opts, :redirect_uri)
266
266
+
key = Keyword.get_lazy(opts, :key, &get_key/0)
267
267
+
client_id = Keyword.get_lazy(opts, :client_id, &Config.client_id/0)
268
268
+
redirect_uri = Keyword.get_lazy(opts, :redirect_uri, &Config.redirect_uri/0)
273
269
274
270
client_assertion =
275
271
create_client_assertion(key, client_id, authz_metadata.issuer)
···
320
316
{:ok, tokens(), String.t()} | {:error, any()}
321
317
def refresh_token(refresh_token, dpop_key, issuer, token_endpoint, opts \\ []) do
322
318
opts =
323
323
-
Keyword.validate!(opts,
324
324
-
key: get_key(),
325
325
-
client_id: Config.client_id(),
326
326
-
redirect_uri: Config.redirect_uri(),
327
327
-
scopes: Config.scopes()
319
319
+
Keyword.validate!(
320
320
+
opts,
321
321
+
[:key, :client_id, :redirect_uri, :scopes]
328
322
)
329
323
330
330
-
key = Keyword.get(opts, :key)
331
331
-
client_id = Keyword.get(opts, :client_id)
324
324
+
key = Keyword.get_lazy(opts, :key, &get_key/0)
325
325
+
client_id = Keyword.get_lazy(opts, :client_id, &Config.client_id/0)
332
326
333
327
client_assertion =
334
328
create_client_assertion(key, client_id, issuer)