Skip to content

Commit

Permalink
Update README.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-viskov committed May 11, 2021
1 parent 6e65828 commit c34eee7
Showing 1 changed file with 98 additions and 86 deletions.
184 changes: 98 additions & 86 deletions README.rst
Expand Up @@ -239,8 +239,89 @@ To check which services we have access to:
if message_launch.has_nrps():
# Has Names and Roles Service
Usage with Flask
================

Open Id Connect Login Request
-----------------------------

This is a draft of an API endpoint. Wrap it in a library of your choice.

Create a ``FlaskRequest`` adapter. Then create an instance of ``FlaskOIDCLogin``. The ``redirect`` method will return an instance of ``werkzeug.wrappers.Response`` that points to the LTI platform if login was successful. Make sure to handle exceptions.

.. code-block:: python
from flask import request, session
from pylti1p3.flask_adapter import (FlaskRequest, FlaskOIDCLogin)
def login(request_params_dict):
tool_conf = ... # See Configuration chapter above
# FlaskRequest by default use flask.request and flask.session
# so in this case you may define request object without any arguments:
request = FlaskRequest()
# in case of using different request object (for example webargs or something like this)
# you may pass your own values:
request = FlaskRequest(
cookies=request.cookies,
session=session,
request_data=request_params_dict,
request_is_secure=request.is_secure
)
oidc_login = FlaskOIDCLogin(
request=request,
tool_config=tool_conf,
session_service=FlaskSessionService(request),
cookie_service=FlaskCookieService(request)
)
return oidc_login.redirect(request.get_param('target_link_uri'))
LTI Message Launches
--------------------

This is a draft of an API endpoint. Wrap it in a library of your choice.

Create a ``FlaskRequest`` adapter. Then create an instance of ``FlaskMessageLaunch``. This lets you access data from the LTI launch message if the launch was successful. Make sure to handle exceptions.

.. code-block:: python
from flask import request, session
from werkzeug.utils import redirect
from pylti1p3.flask_adapter import (FlaskRequest, FlaskMessageLaunch)
def launch(request_params_dict):
tool_conf = ... # See Configuration chapter above
request = FlaskRequest()
# or
request = FlaskRequest(
cookies=...,
session=...,
request_data=...,
request_is_secure=...
)
message_launch = FlaskMessageLaunch(
request=request,
tool_config=tool_conf
)
email = message_launch.get_launch_data().get('email')
# Place your user creation/update/login logic
# and redirect to tool content here
Accessing Cached Launch Requests
--------------------------------
================================

It is likely that you will want to refer back to a launch later during subsequent requests. This is done using the launch id to identify a cached request. The launch id can be found using:

Expand All @@ -264,7 +345,7 @@ Once retrieved, you can call any of the methods on the launch object as normal,
# Has Assignments and Grades Service
Deep Linking Responses
----------------------
======================

If you receive a deep linking launch, it is very likely that you are going to want to respond to the deep linking request with resources for the platform.

Expand Down Expand Up @@ -298,7 +379,7 @@ Alternatively you can just request the signed JWT that will need posting back to
deep_link.get_response_jwt([resource1, resource2])
Names and Roles Service
-----------------------
=======================

Before using names and roles, you should check that you have access to it:

Expand All @@ -320,7 +401,7 @@ From the service we can get a list of all members by calling:
members = nrps.get_members()
Assignments and Grades Service
------------------------------
==============================

Before using assignments and grades, you should check that you have access to it:

Expand Down Expand Up @@ -368,8 +449,20 @@ If you want to send multiple types of grade back, that can be done by specifying
If a lineitem with the same ``tag`` exists, that lineitem will be used, otherwise a new lineitem will be created.

Data privacy launch
===================

Data Privacy Launch is a new optional LTI 1.3 message type that allows LTI-enabled tools to assist administrative
users in managing and executing requests related to data privacy.

.. code-block:: python
data_privacy_launch = message_launch.is_data_privacy_launch()
if data_privacy_launch:
user = message_launch.get_privacy_launch_user()
Check user's role after LTI launch
----------------------------------
==================================

.. code-block:: python
Expand All @@ -381,87 +474,6 @@ Check user's role after LTI launch
user_is_observer = message_launch.check_observer_access()
user_is_transient = message_launch.check_transient()
Usage with Flask
================

Open Id Connect Login Request
-----------------------------

This is a draft of an API endpoint. Wrap it in a library of your choice.

Create a ``FlaskRequest`` adapter. Then create an instance of ``FlaskOIDCLogin``. The ``redirect`` method will return an instance of ``werkzeug.wrappers.Response`` that points to the LTI platform if login was successful. Make sure to handle exceptions.

.. code-block:: python
from flask import request, session
from pylti1p3.flask_adapter import (FlaskRequest, FlaskOIDCLogin)
def login(request_params_dict):
tool_conf = ... # See Configuration chapter above
# FlaskRequest by default use flask.request and flask.session
# so in this case you may define request object without any arguments:
request = FlaskRequest()
# in case of using different request object (for example webargs or something like this)
# you may pass your own values:
request = FlaskRequest(
cookies=request.cookies,
session=session,
request_data=request_params_dict,
request_is_secure=request.is_secure
)
oidc_login = FlaskOIDCLogin(
request=request,
tool_config=tool_conf,
session_service=FlaskSessionService(request),
cookie_service=FlaskCookieService(request)
)
return oidc_login.redirect(request.get_param('target_link_uri'))
LTI Message Launches
--------------------

This is a draft of an API endpoint. Wrap it in a library of your choice.

Create a ``FlaskRequest`` adapter. Then create an instance of ``FlaskMessageLaunch``. This lets you access data from the LTI launch message if the launch was successful. Make sure to handle exceptions.

.. code-block:: python
from flask import request, session
from werkzeug.utils import redirect
from pylti1p3.flask_adapter import (FlaskRequest, FlaskMessageLaunch)
def launch(request_params_dict):
tool_conf = ... # See Configuration chapter above
request = FlaskRequest()
# or
request = FlaskRequest(
cookies=...,
session=...,
request_data=...,
request_is_secure=...
)
message_launch = FlaskMessageLaunch(
request=request,
tool_config=tool_conf
)
email = message_launch.get_launch_data().get('email')
# Place your user creation/update/login logic
# and redirect to tool content here
Cookies issues in the iframes
=============================

Expand Down

0 comments on commit c34eee7

Please sign in to comment.