Comments (11)
I was thinking about this API
defmodule Guardian.DB.Adapter do
@moduledoc """
The Guardian DB Adapter.
This behaviour allows to use any storage system
for Guardian Tokens.
"""
@typep query :: Ecto.Query.t()
@typep schema :: Ecto.Schema.t()
@typep schema_or_changeset :: schema() | Ecto.Changeset.t()
@typep queryable :: query() | schema()
@typep opts :: keyword()
@typep id :: pos_integer() | binary() | Ecto.UUID.t()
@callback one(queryable()) :: nil | schema()
@callback get(queryable(), id()) :: nil | schema()
@callback insert(schema_or_changeset()) :: {:ok, schema()}
@callback delete(schema_or_changeset()) :: {:ok, schema()}
@callback delete_all(queryable()) :: {:ok, pos_integer()}
@callback delete_all(queryable(), opts()) :: {:ok, pos_integer()}
end
@alexfilatov do you think it's enough to bring Redis, or any storage adapter to Guardian.DB
?
from guardian_db.
This is a great idea! @alexfilatov if you want to open a draft PR to solicit feedback feel free 👍
from guardian_db.
Hello there again @doomspork and @aleDsz!
Sorry for the long reply, got back to this one eventually.
I got a slightly different idea.
I started working on the PR for guardian_db
but one thing was very annoying for me - why would guardian_db have some new dependencies (on redix
and jason
) just because of a new Redis repo? What if the user will not use Redis as storage for tokens but still have those dependencies?
Also, I read a great article from @savonarola about SOLID principles in Elixir and that was literally my case!
So I started working on https://github.com/alexfilatov/guardian_redis - a plugin
for guardian_db
. The only thing user need to do is to include this library in deps
and change repo
settings (well, Redis settings as well, but this goes without saying:)
This is still a Work in Progress but I would like to hear your early feedback, please.
from guardian_db.
@alexfilatov I forgot about something, I only see {:ok, ....}
success responses in the callback, is that correct? or do we need some error tuple response as well?
from guardian_db.
I think it's a good idea, and we can improve that using an Adapter
for token storage, using the same @behaviour
to allow users to change to their preference, and ur repo can become and plugin adapter
for Redis.
What u think?
from guardian_db.
@alexfilatov welcome to add some adapter pattern around GuardianDB, make sure to tag me on it ... I keep losing notifications, I will help you to review and merge it
from guardian_db.
love it @aleDsz, will work on PR asap, will let you guy know when ready!
from guardian_db.
@alexfilatov i can help if u want to. I was thinking about to ask your help to make a good integration using this behaviour to test the idea and checking if it would work with Ecto and Redix
from guardian_db.
this one solved by adding an adapter here #126 and implementing a Redis plugin https://github.com/alexfilatov/guardian_redis
from guardian_db.
this is a great catch @yordis! yes, we need {:error, ... }
as well, e.g.
@callback insert(schema_or_changeset()) :: {:ok, schema()} | {:error, Ecto.Changeset.t()}
Will prepare new PR.
from guardian_db.
Hey @yordis, made a PR, could you please have a look? ^^
from guardian_db.
Related Issues (20)
- separated token schemes HOT 4
- hash of tokens HOT 2
- Revoking Token thats already been removed throws error rather than returning error HOT 1
- Dependency Update
- Changelog updates since 0.8 HOT 3
- How to add more columns to 'guardian_tokens' table? HOT 5
- Compatibility with Guardian 2.0 HOT 2
- Idea: Use gen server to avoid round-trip to database HOT 9
- Update ecto_sql(currently at 3.1.0) dependency to the latest version HOT 1
- Do not fix ecto version HOT 2
- Documentation: need to update migrations if using non-default table name
- Ecto.StaleEntryError when using Guardian.DB.on_revoke HOT 8
- cut a new release? HOT 1
- Add a column to optionally store the jti of the refresh token used to generate an access token. HOT 2
- Publish new release HOT 1
- `Guardian.DB.Sweeper` incompatible with old worker API HOT 1
- function Guardian.DB.on_refresh/2 is undefined or private HOT 3
- guardian_db fails to compile with Ecto 3 rc (undefined function migrations_path/1) HOT 20
- how to use in two or more servers with login just one time? share pwd HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guardian_db.