1
1
package auth
2
2
3
3
import (
4
- "context"
5
- "fmt"
4
+ "context"
5
+ "fmt"
6
+ "github.com/axone-protocol/axone-sdk/credential"
6
7
7
- "github.com/axone-protocol/axone-sdk/dataverse"
8
+ "github.com/axone-protocol/axone-sdk/dataverse"
8
9
)
9
10
10
11
// Proxy acts as the entrypoint of a service and is responsible for authenticating any identity willing to conduct some
@@ -14,35 +15,40 @@ import (
14
15
// It is not responsible or aware of the communication protocol, which means it only returns information on the identity
15
16
// if authentic and won't for example issue a JWT token, this is out of its scope.
16
17
type Proxy interface {
17
- // Authenticate verifies the authenticity and integrity of the provided credential before resolving on-chain
18
- // authorized actions with the proxied service by querying the service's governance.
19
- Authenticate (ctx context.Context , credential []byte ) (* Identity , error )
18
+ // Authenticate verifies the authenticity and integrity of the provided credential before resolving on-chain
19
+ // authorized actions with the proxied service by querying the service's governance.
20
+ Authenticate (ctx context.Context , credential []byte ) (* Identity , error )
20
21
}
21
22
22
23
type authProxy struct {
23
- dvClient dataverse.Client
24
- govAddr string
24
+ dvClient dataverse.Client
25
+ govAddr string
26
+ authParser credential.Parser [* credential.AuthClaim ]
25
27
}
26
28
27
29
func NewProxy (govAddr string , dvClient dataverse.Client ) Proxy {
28
- return & authProxy {
29
- dvClient : dvClient ,
30
- govAddr : govAddr ,
31
- }
30
+ return & authProxy {
31
+ dvClient : dvClient ,
32
+ govAddr : govAddr ,
33
+ authParser : credential .NewAuthParser (),
34
+ }
32
35
}
33
36
34
37
func (a * authProxy ) Authenticate (ctx context.Context , credential []byte ) (* Identity , error ) {
35
- // parse credential
36
- // verify signature
37
- // get authorized actions from governance, ex:
38
- did := "did:key:example"
39
- res , err := a .dvClient .ExecGov (ctx , a .govAddr , fmt .Sprintf ("can(Action,'%s')." , did ))
40
- if err != nil {
41
- return nil , err
42
- }
43
-
44
- return & Identity {
45
- DID : did ,
46
- AuthorizedActions : res .([]string ),
47
- }, nil
38
+ authClaim , err := a .authParser .ParseSigned (credential )
39
+ if err != nil {
40
+ return nil , fmt .Errorf ("failed to parse credential: %w" , err )
41
+ }
42
+
43
+ // TODO: get authorized actions from governance, ex:
44
+ did := "did:key:example"
45
+ res , err := a .dvClient .ExecGov (ctx , a .govAddr , fmt .Sprintf ("can(Action,'%s')." , did ))
46
+ if err != nil {
47
+ return nil , err
48
+ }
49
+
50
+ return & Identity {
51
+ DID : authClaim .ID ,
52
+ AuthorizedActions : res .([]string ),
53
+ }, nil
48
54
}
0 commit comments