caffeinehit / django-oauth2-provider

Provide OAuth2 access to your app
http://www.caffeinehit.com/work/code/django-oauth2-provider/
MIT License
337 stars 260 forks source link

Human-friendly scope descriptions #8

Open drdaeman opened 11 years ago

drdaeman commented 11 years ago

I'd suggest adding human-readable scope descriptions in configuration, instead of keeping them template-only hack.

I.e. I mean something like this:

OAUTH_SCOPES = (
    (READ, "read", _(u"Read your data")),
    (READ_WRITE, "write", _(u"Write your data")),
)

Or, maybe, separating permissions from scopes:

OAUTH_PERMISSIONS = {
    READ: _(u"Read your data"),
    WRITE: _(u"Write your data"),
}
assert all((is_power_of_two(k) for k in OAUTH_PERMISSIONS.keys()))
OAUTH_SCOPES = (
    (READ, "read"),
    (READ_WRITE, "write"),
)

Then, instead of {% if permission == "read" %}...{% else %}...{% endif %} hack do something like:

{% for permission in oauth_data.scope|scopes_permissions %}
    <li>{{ permission }}</li>
{% endfor %}

However, I'm unsure on how this should be actually done.

drdaeman commented 11 years ago

My first attempt at it was backwards-compatible — a relatively simple addition of third field to OAUTH_SCOPES.

Then I've thought that bit mangling is a bit too tricky and scopes should be better represented as DB models. So I've did this change. I haven't yet tested this except for running existing testsuite, though. And I did a mistake, starting the branch from a wrong commit, so this probably won't apply cleanly.

eculver commented 10 years ago

@drdaeman Thanks for your help. I'd like to discuss this issue more over something more concrete. Would you be interested in creating a clean pull request?