Skip to content

Commit

Permalink
FIRST RELEASE
Browse files Browse the repository at this point in the history
  • Loading branch information
rscarrera27 committed Jun 6, 2018
1 parent 74752e5 commit 81f77ee
Show file tree
Hide file tree
Showing 12 changed files with 490 additions and 177 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ ENV/

# mypy
.mypy_cache/
*.xml
.idea/Auge.iml
89 changes: 87 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,87 @@
# JWTmaker
simple JWT auth library
# Flask-GraphQL-Auth

## Installation
```sh
pip install flask_graphql_auth
```

## usuage
```python
from flask import Flask
import graphene
from flask_graphql_auth import *
from flask_graphql import GraphQLView

app = Flask(__name__)
auth = GraphToken(app)

app.config["JWT_SECRET_KEY"] = "something" # change this!
app.config["REFRESH_EXP_LENGTH"] = 30
app.config["ACCESS_EXP_LENGTH"] = 10


class AuthMutation(graphene.Mutation):
class Arguments(object):
username = graphene.String()
password = graphene.String()

access_token = graphene.String()
refresh_token = graphene.String()

def mutate(self, info, username, password):

return AuthMutation(access_token=create_access_token(username),
refresh_token=create_refresh_token(username))


class ProtectedMutation(graphene.Mutation):
class Arguments(object):
token = graphene.String()

ok = graphene.Boolean()

@jwt_required
def mutate(self, info, token):
return AuthMutation(ok=True)


class RefreshMutation(graphene.Mutation):
class Arguments(object):
token = graphene.String()

new_token = graphene.String()

@jwt_refresh_token_required
def mutate(self, info, token):
current_user = get_jwt_identity()
return RefreshMutation(new_token=create_access_token(identity=current_user))


class Mutation(graphene.ObjectType):
auth = AuthMutation.Field()
refresh = RefreshMutation.Field()
protected = ProtectedMutation.Field()


class Query(graphene.ObjectType):
protected = graphene.String(message=graphene.String(),
token=graphene.String())

@jwt_required
def resolve_protected(self, info, token, message):
return message


schema = graphene.Schema(query=Query, mutation=Mutation)

app.add_url_rule(
'/graphql',
view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)
)

if __name__ == '__main__':
app.run(debug=True)
```

## docs
coming soon
1 change: 0 additions & 1 deletion auge/__init__.py

This file was deleted.

133 changes: 0 additions & 133 deletions auge/api_auge.py

This file was deleted.

35 changes: 0 additions & 35 deletions auge/type_auge.py

This file was deleted.

74 changes: 74 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from flask import Flask
import graphene
from flask_graphql_auth import *
from flask_graphql import GraphQLView

app = Flask(__name__)
auth = GraphToken(app)

app.config["JWT_SECRET_KEY"] = "something" # change this!
app.config["REFRESH_EXP_LENGTH"] = 30
app.config["ACCESS_EXP_LENGTH"] = 10


class AuthMutation(graphene.Mutation):
class Arguments(object):
username = graphene.String()
password = graphene.String()

access_token = graphene.String()
refresh_token = graphene.String()

def mutate(self, info, username, password):

return AuthMutation(access_token=create_access_token(username),
refresh_token=create_refresh_token(username))


class ProtectedMutation(graphene.Mutation):
class Arguments(object):
token = graphene.String()

ok = graphene.Boolean()

@jwt_required
def mutate(self, info, token):
return AuthMutation(ok=True)


class RefreshMutation(graphene.Mutation):
class Arguments(object):
token = graphene.String()

new_token = graphene.String()

@jwt_refresh_token_required
def mutate(self, info, token):
current_user = get_jwt_identity()
return RefreshMutation(new_token=create_access_token(identity=current_user))


class Mutation(graphene.ObjectType):
auth = AuthMutation.Field()
refresh = RefreshMutation.Field()
protected = ProtectedMutation.Field()


class Query(graphene.ObjectType):
protected = graphene.String(message=graphene.String(),
token=graphene.String())

@jwt_required
def resolve_protected(self, info, token, message):
return message


schema = graphene.Schema(query=Query, mutation=Mutation)

app.add_url_rule(
'/graphql',
view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)
)

if __name__ == '__main__':
app.run(debug=True)
3 changes: 3 additions & 0 deletions flask_graphql_auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .decorators import *
from .graph_token import *
from .util import *
Loading

0 comments on commit 81f77ee

Please sign in to comment.