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

OAuth logic. #2

Closed
wants to merge 1 commit into from
Closed

OAuth logic. #2

wants to merge 1 commit into from

Conversation

kzaher
Copy link
Member

@kzaher kzaher commented May 10, 2017

This is an example of generic OAuth logic made by using system operator.

Generic OAuth logic is ~150 lines long in Sources/RxOAuth/RxOAuth.swift

There are also unit tests included, and it seems to work ok :)

  • There is optional callback that enables validating token expiration date and preemptive token refresh shouldRefreshNow
  • In case OAuth authenticated call returns .tokenInvalidated, oauth token is refreshed and original request is retried exactly once with the new token.
  • Token is only invalidated in case token refresh call returns .tokenInvalidated (usually 401). This is to guard against buggy server implementations (been there, done that :) In case any other call returns .tokenInvalidated (usually 401), it will only initiate token refresh logic.
  • There are no assumptions about OAuth token structure, it's a generic value type.

There are 2 ways how one could use this.

  • Version where token persistence is handled manually -> OAuth.feedback provides feedback loops for that external state storage.
  • Version where external token persistence can be updated with latest token version from OAuthExecutor.state. E.g. In case of logout, OAuthExecutor.state would return .tokenInvalidated. This is OAuth.system interface.

This is the first version to try out the concept. Doesn't look too bad :) Maybe it can be simplified more.

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

1 participant