-
Notifications
You must be signed in to change notification settings - Fork 35
[6.x] Credential managers #116
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
[6.x] Credential managers #116
Conversation
Apply fixes from StyleCI
|
@hailwood This one's now ready for your review. 🎉 |
|
Hey @JamesFreeman, Nice work here! With I.e. (feel free to come up with a better name) ModelStore::useCredentialStorageModel(Settings::first());
ModelStore::getCredentialStorageModel();Prior Art Cashier::useSubscriptionModel(Subscription::class);
Cashier::useSubscriptionItemModel(SubscriptionItem::class);Sanctum Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);Passport Passport::useTokenModel(Token::class);
Passport::useRefreshTokenModel(RefreshToken::class);
Passport::useAuthCodeModel(AuthCode::class);
Passport::useClientModel(Client::class);
Passport::usePersonalAccessClientModel(PersonalAccessClient::class);Additional Suggestion ModelStore::resolveCredentialsUsing(function(ModelStore $modelStore) {
if($modelStore->model instanceof User) {
return $modelStore->model->currentTeam->xero;
} elseif($modelStore->model instanceof Setting) {
return $modelStore->model->xero_credentials;
}
throw new Exception('Unknown Xero model store model: ' . get_class($modelStore->model));
});
// also support just setting the attribute (which would be the default)
ModelStore::resolveCredentialsUsing('xero_credentials');What are your thoughts on these? |
Apply fixes from StyleCI
|
Really good feedback, I've now refactored the code to use a base Xero class - I think this is a good first step because I have some more plans to allow users to do easier testing in there apps: Something like this: I've gone with the following methods: public static function useModelStorage(Model $model): void
public static function useAttributeOnModelStore(string $attribute): void
public static function getModelStorage(): Model
public static function getModelAttribute(): stringJust a note, I'll be on holiday from the 16th until the 30th, so if I'm mia, you'll know why :) |
|
Hi @hailwood - I'm back from holiday now - do you have any thoughts on my changes? |
|
Hi @JamesFreeman, I'll have some time to look at these this weekend 👍🏻 Cheers |
hailwood
left a comment
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.
Looking good,
I really like how you've done the data providers 👌
Only two changes requested here - declaring dependencies on the abstract class, and a new custom exception (if you think that's a good idea) and then we're good to go!
| public function getAuthorizationUrl(): string | ||
| { | ||
| $redirectUrl = $this->oauthProvider->getAuthorizationUrl(['scope' => config('xero.oauth.scopes')]); | ||
| $this->session->put('xero_oauth2_state', $this->oauthProvider->getState()); |
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.
We should also declare oauthProvider and session as properties on the BaseCredentialManager too.
…eman/laravel-xero-oauth2 into feature/new-credential-managers
Apply fixes from StyleCI
|
Thanks for the feedback, I've made those changes now. I've done an overall change to how the constructors work on the base credential manager, I resolve from the container instead of dependency injection - which has made things alot simpler in the tests and domain code. I did have one small issue which I believe I've resolved correctly but would be good to get your feedback on. I needed to call the abstracts constructor from |
hailwood
left a comment
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.
Hey @JamesFreeman,
I've added a couple of changes here.
I reckon on the AuthenticatedUserStore we just call the parent constructor anyway, but let me know if I'm missing something :)
| { | ||
| if (! $this->exists()) { | ||
| throw new \Exception('Xero oauth credentials are missing'); | ||
| throw new XeroCredentialsNotFound('Xero oauth credentials are missing'); |
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.
Rather than specifying the same message in multiple places, let's just make these the default values for the $message parameter across each of the exceptions.
…eman/laravel-xero-oauth2 into feature/new-credential-managers
|
I've made most of those changes now - I've left the Exception one as I want do something a bit more and I think we might be at a good point to split that out into a separate PR. |
|
Wicked, I'm happy then. |
|
Yeah, happy if you are. |
|
Very nice work, thanks James. |
Oauth2CredentialManagersStore #107In this PR, I've refactored Credential managers, to all use one BaseCredentialManager, there was too much duplicated code. This will also make it easier for users to create their own managers. I thought this would be a good time to refactor to Data providers.
New Credential Managers
Authenticated user manager
Model manager
It's possible users want to be able point at their own models, for instance they might have a
settingsmodel where they want to store this data.They'll be able to achieve this by calling the following code in their AppServiceProvider:
It would also be possible to change the active model in their middleware. For instance, in my app, we have an "admin" which creates our invoices, but we also allow our clients customers to pay off their invoices via our web routes. (see #105 for more details)