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

feat: New type safe middleware #64

Merged
merged 13 commits into from
Jun 1, 2018
Merged

feat: New type safe middleware #64

merged 13 commits into from
Jun 1, 2018

Conversation

Andrew-Lees11
Copy link
Contributor

@Andrew-Lees11 Andrew-Lees11 commented May 31, 2018

Add the TypeSafeCredentials protocol needed for TypeSafeMiddleware

This has a handle function which will be called by the type-safe middleware to authenticate the user and return an instance of self on success, fail and end the response onFailure or return an error and continue onPass.

inProgress was removed since it isn't getting called by the current credentials and i don't believe we will use it.

redirect unauthorized was added which would redirect the user to a defined url if they failed to authenticate and this is set to have a value.

The plugin headers are set to allow httpBasic to set the headers requesting the user input a username and password.

Id and Provider are needed since these combined will make a unique identifier which is the desired result of this process and will simplify multiple authentication.

On pass will only set the response status if one has not already been set. This is so you can have multiple routes defined on the same path with different auths and if one succeeds then you don't get back unauthorized.

@codecov-io
Copy link

codecov-io commented May 31, 2018

Codecov Report

Merging #64 into master will decrease coverage by 7.18%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #64      +/-   ##
==========================================
- Coverage   65.33%   58.15%   -7.19%     
==========================================
  Files           5        6       +1     
  Lines         251      282      +31     
==========================================
  Hits          164      164              
- Misses         87      118      +31
Flag Coverage Δ
#Credentials 58.15% <0%> (-7.19%) ⬇️
Impacted Files Coverage Δ
Sources/Credentials/TypeSafeCredentials.swift 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5cf5810...95ca8ba. Read the comment docs.

@Andrew-Lees11
Copy link
Contributor Author

Tests are currently failing since this requires TypeSafeMiddleware which will only be available in Kitura 2.4

@ianpartridge ianpartridge requested a review from djones6 June 1, 2018 09:34
Copy link
Contributor

@djones6 djones6 left a comment

Choose a reason for hiding this comment

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

This looks good. Minor comment about refactoring but that could be done another time.

onFailure: { status, headers in
fail(response: response, status: status, headers: headers)
},
onSkip: { status, headers in
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be refactored into a skip() function

@djones6 djones6 merged commit 747e9c8 into master Jun 1, 2018
@djones6 djones6 deleted the newTypeSafeMiddleware branch June 1, 2018 15:55
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.

4 participants