semvec/pypi-packages huggingface dataset:
cognito-code-grant 1.0.30
A middleware and a set of handlers to handle Code Grant authentication with Cognito
License: MIT
Requires Python: >=3.5

## AWS Cognito code grant for Django Rest Framework

This package implements an authentication backend and a set of handlers that enable your application to use 
code grant authentication with AWS Cognito.

The package has been developed by STITCH (https://www.stitchdesignlab.com/)

The documentation for this project is a work-in-progress and is pretty much bare bones. Do not hesitate to 
contact us, or open an issue or PR for contribution.

#### Links
 - [AWS Cognito](https://aws.amazon.com/cognito/)
 - [Django Rest Framework](https://www.django-rest-framework.org/)
 - [Grant types of Cognito explained by AWS](https://aws.amazon.com/blogs/mobile/understanding-amazon-cognito-user-pool-oauth-2-0-grants/)

#### Code grant
Code grant is an OAuth 2.0 flow that allows one to use Cognito as a data store and authentication backend 
for users, while maintaining an updating replica of User and Group information in your applications database.
This way, the application gains the possibility to add custom business logic for users, while the user data is
still stored and managed centrally through Cognito.  


This is especially useful when you are implementing multiple API backends for a platform that consist of multiple 
applications that need to operate on a shared userbase.

See the link above for a detailed explanation of the standard.

#### Installation
You can install this package from pip: `pip install cognito_code_grant`

#### Usage
The implementation consists of an [authentication backend](https://www.django-rest-framework.org/api-guide/authentication/), a login handler, and a logout handler.
To use the backend, simply specify it in your Django Settings:
```
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'cognito_code_grant.authentication.CognitoAuthentication',
        'rest_framework.authentication.BasicAuthentication',
        ...
    )
```
To use the handlers, include them in your URLs using a helper function:
```
from cognito_code_grant.views import include_auth_urls

urlpatterns = [
    path('auth/', include_auth_urls()),
    ...
]
```
Additionally, you will need to set the following settings to point to your instance of Cognito:
```
AUTH_COGNITO_CLIENT_ID = # your client ID
AUTH_COGNITO_CODE_GRANT_URL = # your token endpoint (https://AUTH_DOMAIN/oauth2/token)
AUTH_COGNITO_JWKS_URL = # the url for your JWKs (https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json.)
```

### Development
To run tests, you need to point Django to local test settings, and run the migrations (it will use an sqllite db in a temp folder).  
```python
export DJANGO_SETTINGS_MODULE=tests.settings
python -m django migrate
python -m django test
```

On a merge to master, CICD will automatically create a `patch` version bump, and deploy to pypi. Minor/Major realeases need to be handled manually by the maintainers.
urlock 0.1.22
Library for talking to a running Urbit ship
License: MIT
Keywords: urbit urlock

# Urlock-py

Urlock-py is a python library for connecting to a running urbit ship.

It consists of a single class `Urlock`. Methods are below.

`__init__(url, code)`

    Constructor

    `url` - url to the http interface of the running ship

    `code` - the `+code` of the ship, should never be published


`connect()`

    Connect to the running ship


`poke(ship, app, mark, j)`

    `ship` - ship to send the poke

    `app` - gall application to send the poke to

    `mark` - mark of data sent to the gall application

    `j` - json poke data


`ack(eventId)`

    Send an acknowledgment of receipt of a message so it's cleared from the ship's queue 

    `eventId` - id of the event to acknowledge


`sse_pipe()`

    returns the sseclient object


`subscribe(ship, app, path)`

    `ship` - ship on which the gall application lives

    `app` - gall application to subscribe to

    `path` - path to subscribe on


Follows is a simple script to send a message and subscribe to a chat channel. The specifics require an understanding of the `chat-store` and `chat-hook` interfaces.

```
#!/usr/bin/python3

import urlock
import baseconvert
import time
import random
import dumper

zod = urlock.Urlock("http://localhost:8080", "lidlut-tabwed-pillex-ridrup")
r = zod.connect()
s = zod.subscribe("zod", "chat-store", "/mailbox/~/~zod/mc")

pipe = zod.sse_pipe()

s = baseconvert.base(random.getrandbits(128), 10, 32, string=True).lower()
uid = '0v' + '.'.join(s[i:i+5] for i in range(0, len(s), 5))[::-1]

p = zod.poke("zod", "chat-hook", "json", {"message": {"path": "/~/~zod/mc",
                                                      "envelope": {"uid": uid,
                                                                   "number": 1,
                                                                   "author": "~zod",
                                                                   "when": int(time.time() * 1000),
                                                                   "letter": {"text": "hello world!"}}}})


for m in pipe.events():
   dumper.dump(m)
   dumper.dump(zod.ack(int(m.id)))
```