Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo of full authorization flow #147

Merged
merged 22 commits into from
Aug 31, 2022
Merged

Conversation

andorsk
Copy link
Contributor

@andorsk andorsk commented Jul 18, 2022

a sample demo with a full authorization flow. This is moved from #123. In this, 3 actors are presented:

  1. A university
  2. A student
  3. An employer

The situation is simple: A student graduates from Example University, and Employer now wants to hire the student. This flow outlines how the VC flow works, between the holder, issuer, and verifier. Below is an example of the flow.

image

There is a basic authorization check later, which checks if the employer is OK with the student's VC claims. This is intended to be an explanatory demo, not a production use case.

@andorsk
Copy link
Contributor Author

andorsk commented Jul 18, 2022

@decentralgabe can you take a look at this and let me know if at least the flow is correct and there's nothing wrong conceptually with the demonstration?

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will review in a bit more detail later this week. high level looks good. perhaps worth breaking out into files per party (e.g. holder, verifier, issuer) to make things a bit simpler to follow?

@andorsk
Copy link
Contributor Author

andorsk commented Jul 19, 2022

@decentralgabe yea...we can break it up into multiple files. Good idea. Thanks for the comments.

@andorsk
Copy link
Contributor Author

andorsk commented Jul 26, 2022

I need to eventually bring this back to life. Sorry, been caught up with other things.

@andorsk
Copy link
Contributor Author

andorsk commented Aug 15, 2022

Based on #164 will move over to use_cases.

@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2022

Codecov Report

Merging #147 (39a1d1b) into main (bee622c) will decrease coverage by 0.62%.
The diff coverage is 42.43%.

@@            Coverage Diff             @@
##             main     #147      +/-   ##
==========================================
- Coverage   55.72%   55.10%   -0.63%     
==========================================
  Files          38       40       +2     
  Lines        4163     4368     +205     
==========================================
+ Hits         2320     2407      +87     
- Misses       1449     1565     +116     
- Partials      394      396       +2     
Impacted Files Coverage Δ
did/util.go 37.50% <0.00%> (-5.77%) ⬇️
...ses/apartment_application/apartment_application.go 100.00% <ø> (ø)
example/util.go 6.66% <0.00%> (-13.34%) ⬇️
example/wallet.go 0.00% <0.00%> (ø)
example/use_cases/employer_university_flow/main.go 92.55% <92.55%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@andorsk
Copy link
Contributor Author

andorsk commented Aug 15, 2022

@decentralgabe I think this example will work. I've incorporated the feedback provided. There's things that I would like to improve, in later PR's, but for now if possible I'd like to just get this example in, and improve the example later. It's been 29 days this PR's been open now 🙄 ( mia culpa. it just slid off my radar )

Can you take a look when you have a chance, and we can discuss what changes would be needed for a merge? I'd like to limit future work on it, but I don't want to scrap this work either as it accomplishes I think, it's primary goal of being a simple example to demonstrate a full issuance and verification flow.

I think this with the apartment use case: https://github.com/TBD54566975/ssi-sdk/tree/main/example/use_cases/apartment_application are reasonable reference points for a beginner.

#164

image

@andorsk andorsk marked this pull request as ready for review August 15, 2022 22:08
@andorsk andorsk marked this pull request as draft August 15, 2022 22:56
@andorsk andorsk marked this pull request as ready for review August 15, 2022 22:57
@andorsk
Copy link
Contributor Author

andorsk commented Aug 15, 2022

@decentralgabe please check out the comment above re: my position on this PR.

}

jwk, err := cryptosuite.GenerateJSONWebKey2020(cryptosuite.OKP, cryptosuite.Ed25519)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why not util.HandleExampleError here?

Copy link
Contributor Author

@andorsk andorsk Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. this is because I don't handle the errors here. I handle errors in a single place. This just propagates the error up to the parent function. Basically, propagate the errors until the end, and then determine handling methods. This is from my understanding, best practice:

https://earthly.dev/blog/golang-errors/

The util will kick an exit of a program, which may want to be changed later or handled differently on for some reason, so we want to push the error upstream and handle it there not downstream.

presentationData, err := emp.MakePresentationData("test-id", "id-1")
util.HandleExampleError(err, "failed to create pd")
if dat, err := json.Marshal(presentationData); err == nil {
logrus.Debugf("Presentation Data:\n%v", string(dat))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's an error here, the program will continue?

Copy link
Contributor Author

@andorsk andorsk Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea...the error would be contained to marshaling data. 1) It shouldn't ever really happen ( a failure to marshal ) but I see it as a design choice not a bug if it decides to not exit. There could be cases, where json marshaling fails for some reason.

I'll change it to exit but wanted to note the above. Thanks for the feedback!

return nil, err
}

if dat, err := json.Marshal(knownCred); err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if this is an error? does the "VC issued" line still show?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we just ignore errors that are logging/marshaling json errors, but we can handle them. I don't think they should happen often if at all.

return requestJWTBytes, signer, err
}

func MakePresentationRequest(jwk cryptosuite.JSONWebKey2020, presentationData exchange.PresentationDefinition, targetId string) (pr []byte, signer *cryptosuite.JSONWebKeySigner, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of this?

Copy link
Contributor Author

@andorsk andorsk Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming the question is why private and public mirror functions. So the idea was originally keeping everything private. Then I realized that I wanted to make some public, but I didn't want to refactor the private function calls. I've also seen this done sometimes, in production cases, to keep separation of concerns. Private for functionality, then a wrapper to expose it. If you need to hide the function again, it's trivial and doesn't require as much of a refactor.

That being said: The style of private functions with an external wrapper is probably not useful for this demo, or adds another layer of thought, so I've adjusted things. Thanks for the feedback!

example/wallet.go Outdated Show resolved Hide resolved
}

CustomWriter.WriteNote(fmt.Sprintf("DID for holder is: %s", didStr))
s.AddPrivateKey("main", privKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: what do you think about indexing the keys with integers? this could be simpler...but i also see some benefit in having named keys...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could definitely expand the wallet or do some other types of indexing. Another project I'm working on does this.

To me though, there's another scope of work around making good wallets, and the scope of this PR is to make just a wallet that is simple in functionality and gives the general "idea". As long as it works, and can educate, at least IMO, it's sufficient for a PR, with a possible follow up on an issue about doing an adjustment.

But ultimately your call. If you want, we can explore different wallet styles in the PR, but it might result in some extra time required for acceptance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree it's for a follow up

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closer!

@andorsk
Copy link
Contributor Author

andorsk commented Aug 31, 2022

@decentralgabe thanks for the review! Hopefully addressed the comments/concerns. Made a few notes about some thoughts. Lmk if there's anything else. Looking forward to getting this in.

did/util.go Outdated Show resolved Hide resolved
did/util.go Outdated Show resolved Hide resolved
Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for seeing this through!

@decentralgabe decentralgabe merged commit 253df3e into TBD54566975:main Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants