Package: nexaas-id-client
# Nexaas ID ClientThis is a client for Nexaas ID. It brings support for generic OAuthauthentication and for Django and Flask frameworks.## OAuth clientThe general use is:```pythonfrom nexaas_id_client import NexaasIDOAuthClientclient = NexaasIDOAuthClient(application_token,application_secret,server='id.nexaas.com',redirect_uri=application_callback,)```The authorization URL can get from `client.authorize_url` and the access tokencan be retrieve in the callback procedure from `client.get_access_token(code)`,where `code` is the access grant code.### Settings for Django and Flask- `NEXAAS_ID_CLIENT_ID`: the application token- `NEXAAS_ID_CLIENT_SECRET`: the application secret- `NEXAAS_ID_HOST`: the Nexaas ID host- `NEXAAS_ID_CLIENT_SCOPE`: the scope (can be `None`)### DjangoIn Django you must include the following path to the main `urlpatterns`:```pythonpath('oauth/', include('nexaas_id_client.support.django.urls'))```The views that requires authorized access must be decorated:```pythonfrom nexaas_id_client.support.django.decorators import authorization_required@authorization_requireddef index(request, api_client: 'nexaas_id_client.NexaasIDClient') -> 'django.http.request.HttpResponse':...```Your view must expect an `api_client` as argument – see bellow. Anyway you canretrieve de access token from the session, under the key `oauth_access_token`.In order to logout, use the app route `signout`. The query string key`next_url` inform where to redirect after sign out.**Caution:** If the view returns falsy (`None`, `False`, `0`, `""`, et cetera),the `authorization_required` decorator redirects to sign out URL.### FlaskThe Flask support supplies a blueprint capable of deal with Nexaas ID OAuth.The use:```pythonfrom flask import Flaskfrom nexaas_id_client.support.flask import oauthapp = Flask(__name__)app.register_blueprint(oauth, url_prefix='/oauth')```The decorator is similar to Django support:```pythonfrom nexaas_id_client.support.flask import authorization_required, oauth...@app.route('/')@authorization_requireddef index(api_client: 'nexaas_id_client.NexaasIDClient') -> 'flask.Response':...```Your view must expect an `api_client` as argument – see bellow. Anyway you canretrieve de access token from the session, under the key `oauth_access_token`.In order to logout, use the blueprint route `signout`. The query string key`next_url` inform where to redirect after sign out.## API clientThe API client is responsible for dealing with Nexaas ID API.You can get it this way:```pythonapi_client = NexaasIDClient.from_oauth(client.get_access_token(code),client=client,)```Where `client` is the OAuth client and `code` is the access grant code.But, if you are using a framework support, you don’t need to do it: viewsdecorated by `authorization_required` will receive an API client ready to use.### Resource APIThe API client attributes:- `access_token: str` – the access token- `refresh_token: str` – the refresh token- `scope: str` – the allowed scope- `token: OAuthToken` – a token wrapper- `id: str` – the client id- `secret: str` – the client secret- `server: urllib.parse.ParseResult` – the Nexaas ID server- `personal_info: PersonalInfo` – the user’s personal data- `professional_info: ProfessionalInfo` – the user’s professional data- `emails: Emails` – a dictionary containing user id and the its e-mails list- `contacts: Contacts` – a dictionary containing user id and its phone numbersand eventually other contacts- `invite(email: str) -> Invitation` – invite another user to the currentapplicationThe classes `PersonalInfo`, `ProfessionalInfo`, `Emails`, `Contacts` and`Invitation` are built on demand metaprogrammatically, and have an `id`attribute (`uuid.UUID`) at least.Other attributes you may expect:- `PersonalInfo`- `full_name: str`- `first_name: str`- `last_name: str`- `nickname: str`- `email: str`- `birth: datetime.date`- `gender: str`- `language: str`- `picture: str`- `timezone: str`- `country: str`- `city: str`- `bio: str`- `ProfessionalInfo`- `profession: str`- `company: str`- `position: str`- `Emails`- `emails: List[str]`- `Contacts`:- `phone_numbers: List[str]`- `Invitation`:- `email` (invited user)- `requester` (inviter id)- `OAuthToken`:- `access_token: str`- `refresh_token: str`- `expired_at: datetime.datetime`- `scope: str`- `expired: bool` (maybe not present)