• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

malach-it / boruta_auth / 954161a5b397cc94069ec938dc16fcb785e37074-PR-29

18 Jan 2025 10:28PM UTC coverage: 85.651% (-4.3%) from 89.944%
954161a5b397cc94069ec938dc16fcb785e37074-PR-29

Pull #29

github

patatoid
refactor verifiable credentials status tokens
Pull Request #29: Agent credentials PoC

188 of 304 new or added lines in 20 files covered. (61.84%)

3 existing lines in 1 file now uncovered.

1552 of 1812 relevant lines covered (85.65%)

85.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/lib/boruta/config.ex
1
defmodule Boruta.Config do
2
  @moduledoc """
3
  Utilities to access Boruta configuration ad set defaults.
4

5
  Boruta configuration can be set as following in `config.exs` overriding following default configuration
6
  ```
7
  config :boruta, Boruta.Oauth,
8
    repo: MyApp.Repo, # mandatory
9
    cache_backend: Boruta.Cache,
10
    contexts: [
11
      access_tokens: Boruta.Ecto.AccessTokens,
12
      agent_tokens: Boruta.Ecto.AgentTokens,
13
      clients: Boruta.Ecto.Clients,
14
      codes: Boruta.Ecto.Codes,
15
      preauthorized_codes: Boruta.Ecto.PreauthorizedCodes,
16
      resource_owners: MyApp.ResourceOwners, # mandatory for user flows
17
      scopes: Boruta.Ecto.Scopes,
18
      requests: Boruta.Ecto.Requests,
19
      credentials: Boruta.Ecto.Credentials,
20
      signatures: Boruta.Internal.Signatures
21
    ],
22
    max_ttl: [
23
      authorization_code: 60,
24
      authorization_request: 60,
25
      access_token: 60 * 60 * 24,
26
      agent_token: 60 * 60 * 24 * 30,
27
      id_token: 60 * 60 * 24,
28
      refresh_token: 60 * 60 * 24 * 30
29
    ],
30
    ebsi_did_resolver_base_url: "https://api-conformance.ebsi.eu/did-registry/v5",
31
    did_resolver_base_url: "https://api.godiddy.com/1.0.0/universal-resolver",
32
    did_registrar_base_url: "https://api.godiddy.com/1.0.0/universal-registrar",
33
    universal_did_auth: %{
34
      type: "bearer",
35
      token: DID_API_KEY
36
    },
37
    token_generator: Boruta.TokenGenerator,
38
    issuer: "boruta"
39
  ```
40
  > Note: To use the did resolver and registrar services, you must provide a compliant server. Here the default is set to the [Godiddy](https://godiddy.com/) server which require an API key to perform the requests.
41
  """
42

43
  @defaults cache_backend: Boruta.Cache,
44
            contexts: [
45
              access_tokens: Boruta.Ecto.AccessTokens,
46
              agent_tokens: Boruta.Ecto.AgentTokens,
47
              clients: Boruta.Ecto.Clients,
48
              codes: Boruta.Ecto.Codes,
49
              preauthorized_codes: Boruta.Ecto.PreauthorizedCodes,
50
              resource_owners: nil,
51
              scopes: Boruta.Ecto.Scopes,
52
              requests: Boruta.Ecto.Requests,
53
              credentials: Boruta.Ecto.Credentials,
54
            ],
55
            max_ttl: [
56
              authorization_request: 300,
57
              authorization_code: 60,
58
              access_token: 60 * 60 * 24,
59
              agent_token: 60 * 60 * 24 * 30,
60
              id_token: 60 * 60 * 24,
61
              refresh_token: 60 * 60 * 24 * 30
62
            ],
63
            ebsi_did_resolver_base_url: "https://api-conformance.ebsi.eu/did-registry/v5",
64
            did_resolver_base_url: "https://api.godiddy.com/1.0.0/universal-resolver",
65
            did_registrar_base_url: "https://api.godiddy.com/1.0.0/universal-registrar",
66
            signature_credentials_base_url: "https://api.godiddy.com/1.0.0/universal-issuer/credentials/issue",
67
            universal_keys_base_url: "https://api.godiddy.com/0.1.0/wallet-service/keys",
68
            universal_sign_base_url: "https://api.godiddy.com/0.1.0/wallet-service/keys/sign",
69
            universal_did_auth: %{
70
              type: "bearer",
71
              token: nil
72
            },
73
            token_generator: Boruta.TokenGenerator,
74
            issuer: "boruta"
75

76
  @spec repo() :: module()
77
  @doc false
78
  def repo do
79
    Keyword.fetch!(oauth_config(), :repo)
1,406✔
80
  end
81

82
  @spec cache_backend() :: module()
83
  @doc false
84
  def cache_backend do
85
    Keyword.fetch!(oauth_config(), :cache_backend)
2,267✔
86
  end
87

88
  @spec access_token_max_ttl() :: integer()
89
  @doc false
90
  def access_token_max_ttl do
91
    Keyword.fetch!(oauth_config(), :max_ttl)[:access_token]
111✔
92
  end
93

94
  @spec agent_token_max_ttl() :: integer()
95
  @doc false
96
  def agent_token_max_ttl do
97
    Keyword.fetch!(oauth_config(), :max_ttl)[:agent_token]
111✔
98
  end
99

100
  @spec authorization_code_max_ttl() :: integer()
101
  @doc false
102
  def authorization_code_max_ttl do
103
    Keyword.fetch!(oauth_config(), :max_ttl)[:authorization_code]
111✔
104
  end
105

106
  @spec authorization_request_max_ttl() :: integer()
107
  @doc false
108
  def authorization_request_max_ttl do
109
    Keyword.fetch!(oauth_config(), :max_ttl)[:authorization_request]
111✔
110
  end
111

112
  @spec id_token_max_ttl() :: integer()
113
  @doc false
114
  def id_token_max_ttl do
115
    Keyword.fetch!(oauth_config(), :max_ttl)[:id_token]
111✔
116
  end
117

118
  @spec refresh_token_max_ttl() :: integer()
119
  @doc false
120
  def refresh_token_max_ttl do
121
    Keyword.fetch!(oauth_config(), :max_ttl)[:refresh_token]
111✔
122
  end
123

124
  @spec token_generator() :: module()
125
  @doc false
126
  def token_generator do
127
    Keyword.fetch!(oauth_config(), :token_generator)
228✔
128
  end
129

130
  @spec access_tokens() :: module()
131
  @doc false
132
  def access_tokens do
133
    Keyword.fetch!(oauth_config(), :contexts)[:access_tokens]
112✔
134
  end
135

136
  @spec agent_tokens() :: module()
137
  @doc false
138
  def agent_tokens do
139
    Keyword.fetch!(oauth_config(), :contexts)[:agent_tokens]
20✔
140
  end
141

142
  @spec clients() :: module()
143
  @doc false
144
  def clients do
145
    Keyword.fetch!(oauth_config(), :contexts)[:clients]
326✔
146
  end
147

148
  @spec codes() :: module()
149
  @doc false
150
  def codes do
151
    Keyword.fetch!(oauth_config(), :contexts)[:codes]
129✔
152
  end
153

154
  @spec preauthorized_codes() :: module()
155
  @doc false
156
  def preauthorized_codes do
157
    Keyword.fetch!(oauth_config(), :contexts)[:preauthorized_codes]
4✔
158
  end
159

160
  @spec scopes() :: module()
161
  @doc false
162
  def scopes do
163
    Keyword.fetch!(oauth_config(), :contexts)[:scopes]
79✔
164
  end
165

166
  @spec requests() :: module()
167
  @doc false
168
  def requests do
169
    Keyword.fetch!(oauth_config(), :contexts)[:requests]
6✔
170
  end
171

172
  @spec credentials() :: module()
173
  @doc false
174
  def credentials do
175
    Keyword.fetch!(oauth_config(), :contexts)[:credentials]
3✔
176
  end
177

178
  @spec resource_owners() :: module()
179
  @doc false
180
  def resource_owners do
181
    case Keyword.fetch!(oauth_config(), :contexts)[:resource_owners] do
172✔
182
      nil ->
183
        raise """
×
184
        Missing configuration for resource_owners context. You can set your own
185
        `Boruta.Oauth.ResourceOwners` behaviour implementation in config:
186

187
          config :boruta, Boruta.Oauth,
188
            repo: MyApp.Repo,
189
            contexts: [
190
              resource_owners: MyApp.ResourceOwners
191
            ]
192
        """
193

194
      module ->
195
        module
172✔
196
    end
197
  end
198

199
  @spec ebsi_did_resolver_base_url() :: String.t()
200
  @doc false
201
  def ebsi_did_resolver_base_url do
202
    Keyword.fetch!(oauth_config(), :ebsi_did_resolver_base_url)
×
203
  end
204

205
  @spec did_resolver_base_url() :: String.t()
206
  @doc false
207
  def did_resolver_base_url do
208
    Keyword.fetch!(oauth_config(), :did_resolver_base_url)
25✔
209
  end
210

211
  @spec did_registrar_base_url() :: String.t()
212
  @doc false
213
  def did_registrar_base_url do
214
    Keyword.fetch!(oauth_config(), :did_registrar_base_url)
×
215
  end
216

217
  @spec signature_credentials_base_url() :: String.t()
218
  @doc false
219
  def signature_credentials_base_url do
NEW
220
    Keyword.fetch!(oauth_config(), :signature_credentials_base_url)
×
221
  end
222

223
  @spec universal_keys_base_url() :: String.t()
224
  @doc false
225
  def universal_keys_base_url do
NEW
226
    Keyword.fetch!(oauth_config(), :universal_keys_base_url)
×
227
  end
228

229
  @spec universal_sign_base_url() :: String.t()
230
  @doc false
231
  def universal_sign_base_url do
NEW
232
    Keyword.fetch!(oauth_config(), :universal_sign_base_url)
×
233
  end
234

235
  @spec universal_did_auth() :: map()
236
  @doc false
237
  def universal_did_auth do
238
    Keyword.fetch!(oauth_config(), :universal_did_auth)
25✔
239
  end
240

241
  @spec issuer() :: String.t()
242
  @doc false
243
  def issuer do
244
    Keyword.fetch!(oauth_config(), :issuer)
164✔
245
  end
246

247
  @spec oauth_config() :: keyword()
248
  @doc false
249
  defp oauth_config do
250
      Keyword.merge(
5,632✔
251
        @defaults,
252
        Application.get_env(:boruta, Boruta.Oauth) || [],
5,632✔
253
        fn _, a, b ->
254
          if Keyword.keyword?(a) && Keyword.keyword?(b) do
11,278✔
255
            Keyword.merge(a, b)
5,632✔
256
          else
257
            b
5,646✔
258
          end
259
        end
260
      )
261
  end
262
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc