Function Repository Resource:

DedicatedPermissionsKey

Source Notebook

Add user-specific permissions keys to a cloud object

Contributed by: Bob Sandheinrich

ResourceFunction["DedicatedPermissionsKey"][co,users]

sets up the CloudObject co with dedicated permissions keys for each of the users.

ResourceFunction["DedicatedPermissionsKey"][]

within a cloud evaluation, retrieves the user data associated with the provided permissions key.

ResourceFunction["DedicatedPermissionsKey"]["StoreResults",expr]

within a cloud evaluation, stores the expr is association with the provided permissions key.

ResourceFunction["DedicatedPermissionsKey"]["RevokeKey"]

within a cloud evaluation, removes the provided permissions key from the permissions of the cloud object.

ResourceFunction["DedicatedPermissionsKey"]["GetResults",co]

retrieves stored results for the CloudObject co.

ResourceFunction["DedicatedPermissionsKey"]["Clear",co]

removes dedicated permissions keys from a cloud object.

Details

The users can be any of the following:
{u1,u2,}a list of arbitrary user information to associate with automatically generated permissions keys
<|"key1"u1,|>manually specified permissions keys for each user
ResourceFunction["DedicatedPermissionsKey"] returns custom urls for each of the users.
ResourceFunction["DedicatedPermissionsKey"] creates a directory with the obscure name "DedicatedPermissionsKeyResourceFunctionStorage" in the cloud file system.
Include ResourceFunction["DedicatedPermissionsKey"]["RevokeKey"] in the body of the cloud evaluation to limit each permissions key to a single use.

Examples

Basic Examples (2) 

Deploy a cloud object:

In[1]:=
co = CloudDeploy[Delayed["Authentication Successful"], Permissions -> "Private"]
Out[1]=

Create custom URLs for each user:

In[2]:=
customlinks = ResourceFunction[
  "DedicatedPermissionsKey", ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"][
  co, {"Thomas", "Winston", "Elena", "Vivianne"}]
Out[2]=

Use one of the URLs:

In[3]:=
Import@URLRead[customlinks["Thomas"]]
Out[3]=

Without the key, execution is denied:

In[4]:=
URLRead[co[[1]]]
Out[4]=

Create a cloud object that returns the identity of a permissions key owner:

In[5]:=
co = CloudDeploy[
  Delayed["That key belongs to " <> ResourceFunction[
     "DedicatedPermissionsKey", ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"][]], "UserIdentityAPI", Permissions -> "Private"]
Out[5]=

Create permissions keys:

In[6]:=
customlinks = ResourceFunction[
  "DedicatedPermissionsKey", ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"][
  co, {"Jane", "Heidi", "Allison", "Irene", "Zayna"}]
Out[6]=

Use an authenticated link:

In[7]:=
URLExecute[customlinks["Jane"]]
Out[7]=

Scope (5) 

Create an API that allows each user to access the API one time and stores the results of their computation:

In[8]:=
co = CloudDeploy[APIFunction[{"n" -> "Integer"},
   With[{res = IntegerDigits[#n]},
     ResourceFunction[
      "DedicatedPermissionsKey", ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"][
      "StoreResults", <|"Input" -> #n, "Output" -> res|>];
     ResourceFunction[
      "DedicatedPermissionsKey", ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"]["RevokeKey"];
     res
     ] &
   ], "OneTimeFactorAPI", Permissions -> "Private"]
Out[8]=

Create permissions keys:

In[9]:=
customlinks = ResourceFunction[
  "DedicatedPermissionsKey", ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"][co, {"Bob", "Rick", "Cody", "Chris"}]
Out[9]=

Use an authenticated link:

In[10]:=
URLExecute[URLBuild[customlinks["Bob"], {"n" -> "43256"}]]
Out[10]=

Attempting to use the same key again fails:

In[11]:=
URLRead[URLBuild[customlinks["Bob"], {"n" -> "43256"}]]
Out[11]=

Get the stored results:

In[12]:=
ResourceFunction[
 "DedicatedPermissionsKey", ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"]["GetResults", co]
Out[12]=

Properties and Relations (4) 

Deploy a cloud object with dedicated permissions keys:

In[13]:=
co = CloudDeploy[Delayed["Authentication Successful"], Permissions -> "Private"]
Out[13]=
In[14]:=
ResourceFunction[
 "DedicatedPermissionsKey", ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"][co, {"Thomas", "Winston", "Elena", "Vivianne"}]
Out[14]=

Use Information to see the permissions keys:

In[15]:=
Information[co, "Permissions"]
Out[15]=

Clear the dedicated permissions keys:

In[16]:=
ResourceFunction[
 "DedicatedPermissionsKey", ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"]["Clear", co]

The permissions keys are no longer in the cloud object information:

In[17]:=
Information[co, "Permissions"]
Out[17]=

Publisher

Bob

Version History

  • 1.0.0 – 20 September 2022

Related Resources

License Information