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
Added native support for Password Grant flow #179
Conversation
Added support in the accessToken request of additional params.
Thanks, wow, that's quite extensive. A few thoughts:
|
When I started I wanted the password grant flow to only provide a native view and get rid of the web view thing, because using a web view for this flow doesn't really make sens to me. So there would not be About protocols & delegates, I'm not sure what you mean but I think you want the I created the As for the The issue with the registration process is that if there is no clientId and no authorizeURI, it will return as an error, hence I'm bypassing this process. Finally about whitespaces, that's an issue I'm figuring out. I'am actually switching from XCode to AppCode and their indentation/whitespace needs to be matched ;) |
Great, thanks!
Thanks for being so constructive! |
…nd moving the delegate to OAuth2PasswordGrantCustom.
So here is the draft v2 :)
The new protocols are now simpler:
To sum up, here is the default workflow using At some point in the app, we need the user to log in: a The user enters his credentials and hit some "log in" button. As this point, the controller performs (or already did) checks on credentials format, and then call the After some time, the callback is called with the error matching server's response. Once the user is authorized or hit the "actually I don't really want to log in", the login controller calls the |
Great, thanks. This is moving the right direction; I like the protocols now, much slicker! I've set up a password grant flow and I cannot reproduce your web view issue, the flow never attempts to show a login screen. It either throws when there is no username/password or performs the request, as designed in What I think should be done is to weave your additions into the existing flow (I don't think you can deprecate a class that serves as a superclass, or at least it's weird). If you change Do you think this make sense? Minor Things
|
Fixed issue in pbxproj with a mac file
# Conflicts: # Sources/Flows/OAuth2PasswordGrant.swift
Draft v3 is there:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool, we're getting there! Now to the details.
Sources/Base/OAuth2Error.swift
Outdated
@@ -26,6 +26,7 @@ All errors that might occur. | |||
|
|||
The response errors return a description as defined in the spec: http://tools.ietf.org/html/rfc6749#section-4.1.2.1 | |||
*/ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please undo
Sources/Base/OAuth2Error.swift
Outdated
case invalidLoginController(actualType: String, expectedType: String) | ||
|
||
/// There is no delegate. | ||
case noDelegate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be more descriptive, e.g. noPasswordGrantDelegate
.
Sources/Base/OAuth2Error.swift
Outdated
@@ -154,7 +161,7 @@ public enum OAuth2Error: Error, CustomStringConvertible, Equatable { | |||
|
|||
/** | |||
Instantiate the error corresponding to the OAuth2 response code, if it is known. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo
/** | ||
This function is responsible of the login controller presentation. | ||
*/ | ||
func present(loginController: OAuth2LoginController, fromContext context: AnyObject?, animated: Bool) throws |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document parameters
} | ||
|
||
/** | ||
Custom login controllers must adopt this protocol. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No indentation from /**
to text (yes, was new to me too, but Swift wants it).
presentingController?.present(controller, animated: animated) | ||
} | ||
|
||
public func dismissLoginController(animated: Bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document
import Cocoa | ||
|
||
#if !NO_MODULE_IMPORT | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No newline here and after the import
#endif | ||
|
||
|
||
public class OAuth2LoginPresenter: OAuth2LoginPresentable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document
|
||
private var presentedController: NSViewController? | ||
|
||
public func present(loginController: OAuth2LoginController, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document
presentedController = controller | ||
} | ||
|
||
public func dismissLoginController(animated: Bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document
Sources/Base/OAuth2Error.swift
Outdated
@@ -154,7 +160,6 @@ public enum OAuth2Error: Error, CustomStringConvertible, Equatable { | |||
|
|||
/** | |||
Instantiate the error corresponding to the OAuth2 response code, if it is known. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should leave this newline in place for proper docs generation.
The autoDismiss auth config property is now used after a success.
New version there, I hope this is the last ^^ |
Sweet, thanks for hanging in!! |
Will need to make some changes since with these new dependencies, the framework no longer compiles via |
I have changed some of the internals and renamed the protocols (so they are aligned with what's already there). Also Can you test if this still works with your setup? |
There are now some issues with your master branch now:
|
Thanks for testing!
|
As the loginController is presented by the |
Good point! I've added a call to |
Sounds fine to me :) |
Cool, thanks for the feedback and let me know if something else comes up! |
As discussed in #178 , here is a draft for native support in password grant.
I created a new OAuth2PasswordGrantCustom to separate it from the original webview flow.
For now it just bypass the client registration step, as the RFC doesn't mention any requirement of a client_id being send as a parameter of the accessToken request.
I copied the
OAuth2AuthorizeUI
andOAuth2Authorizer
pattern withOAuth2LoginPresentable
andOAuth2LoginPresenter
(macOS is not supported yet though)Let me now if there is something I'm missing or wrong.