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

Enable access for token refresh #31

Merged
merged 15 commits into from
Jun 10, 2022

Conversation

emin-grbo
Copy link
Contributor

As discussed in the issue, enabling access of the oauthUser along with the addition of an optional callback.
#30

Hope it makes sense and this is what you had in mind 🙌

emin added 2 commits June 5, 2022 22:42
To enable access of credentials in case of token refresh
To enable immediate storing and/or access of the newly refreshed token.
Sources/Twift.swift Outdated Show resolved Hide resolved
Sources/Twift.swift Outdated Show resolved Hide resolved
Sources/Twift.swift Outdated Show resolved Hide resolved
emin-grbo and others added 2 commits June 6, 2022 14:25

internal let decoder: JSONDecoder
internal let encoder: JSONEncoder

/// Initialise an instance with the specified authentication type
public init(_ authenticationType: AuthenticationType) {
public init(_ authenticationType: AuthenticationType, onRefresh: (()-> Void)? = nil) {
Copy link
Owner

Choose a reason for hiding this comment

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

Seeing this now, it actually makes more sense to have onRefresh associated with the AuthenticationType:

enum AuthenticationType {
  case oauth2User(user: OAuth2User, onRefresh: (() -> Void)?)
  ...
}

Alternatively, we might want to move to different initialisers for different authentication types. That might actually be nicer from an author perspective.

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 see, yeah, makes sense
Should we then even make it non-optional? I am not sure what the case would be where one would not need a refresh of the token?

I made some changes to the refreshOAuth2AccessToken and moved refreshCompletion from the init to the AuthenticationType

Sources/Twift.swift Outdated Show resolved Hide resolved
@emin-grbo
Copy link
Contributor Author

Also, made some changes to the tests and all instances where oauth2UserAuth was being called.

@emin-grbo emin-grbo requested a review from daneden June 7, 2022 19:20
@daneden daneden merged commit fb6604c into daneden:main Jun 10, 2022
@emin-grbo emin-grbo deleted the enable-access-for-token-refresh branch June 16, 2022 18:27
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.

2 participants