Skip to main content

Slack SCIM API Client

Reason this release was yanked:

had a critical bug

Project description

slack-scim - Slack SCIM API Client

PyPI version Build Status

This library provides ways to call Slack's SCIM APIs in the Pythonic way.

Getting Started

It's pretty easy and intuitive to use this library 😉 Try with your admin user token!

$ pip install slack-scim
Collecting slack-scim
  Using cached slack_scim-1.0.5-py2.py3-none-any.whl (20 kB)
Installing collected packages: slack-scim
Successfully installed slack-scim-1.0.5

$ python

>>> import os
>>> import slack_scim
>>> client = slack_scim.SCIMClient(token=os.environ["SLACK_ADMIN_TOKEN"])

>>> import logging
>>> logging.basicConfig(level=logging.DEBUG)
>>> users = client.search_users(filter="restricted eq 1", count=5)
DEBUG:slack_scim.v1.client:*** SCIM API Request ***
GET https://api.slack.com/scim/v1/Users?filter=restricted+eq+1&count=5
Authorization: (redacted)
Content-type: application/x-www-form-urlencoded;charset=utf-8


DEBUG:slack_scim.v1.client:*** SCIM API Response ***
GET https://api.slack.com/scim/v1/Users?filter=restricted+eq+1&count=5
200 OK
date: Sun, 26 Apr 2020 03:53:44 GMT
server: Apache
strict-transport-security: max-age=31536000; includeSubDomains; preload
referrer-policy: no-referrer
x-slack-backend: h
vary: Accept-Encoding
x-xss-protection: 0
x-frame-options: SAMEORIGIN
connection: close
transfer-encoding: chunked
content-type: application/json; charset=utf-8
x-via: haproxy-www-4mte

{"totalResults":2,"itemsPerPage":2,"startIndex":1,"schemas":["urn:scim:schemas:core:1.0"],"Resources":[{"schemas":["urn:scim:schemas:core:1.0"],"id":"WRDCW4CHX","externalId":"","meta":{"created":"2019-12-14T01:26:43-08:00","location":"https:\/\/api.slack.com\/scim\/v1\/Users\/WRDCW4CHX"},"userName":"steve","nickName":"steve","name":{"givenName":"Hiroyuki","familyName":"Aoki"},"displayName":"steve","profileUrl":"https:\/\/your-domain.enterprise.slack.com\/team\/Steve Aoki","title":"","timezone":"America\/Los_Angeles","active":true,"emails":[{"value":"saoki@example.com","primary":true}],"photos":[{"value":"https:\/\/secure.gravatar.com\/avatar\/111.jpg","type":"photo"}],"groups":[]},{"schemas":["urn:scim:schemas:core:1.0"],"id":"W0107TELUM7","externalId":"","meta":{"created":"2020-03-22T17:38:28-07:00","location":"https:\/\/api.slack.com\/scim\/v1\/Users\/W0107TELUM7"},"userName":"will.i.am","nickName":"will.i.am","name":{"givenName":"William","familyName":"Adams"},"displayName":"will.i.am","profileUrl":"https:\/\/your-domain.enterprise.slack.com\/team\/will.i.am","title":"","timezone":"America\/Los_Angeles","active":true,"emails":[{"value":"will-i-am@example.com","primary":true}],"photos":[{"value":"https:\/\/secure.gravatar.com\/avatar\/222.jpg","type":"photo"}],"groups":[]}]}

>>> users.
users.active          users.external_id     users.id              users.name            users.profile_url     users.start_index     users.to_dict(        
users.display_name    users.from_dict(      users.items_per_page  users.nick_name       users.resources       users.timezone        users.total_results   
users.emails          users.groups          users.meta            users.photos          users.schemas         users.title           users.user_name

>>> list(map(lambda u: u.id, users.resources))
['WRDCW4CHX', 'W0107TELUM7']

>>> list(map(lambda u: u.to_dict()["name"], users.resources))
[{'familyName': 'Aoki', 'givenName': 'Steve'}, {'familyName': 'Adams', 'givenName': 'Adams'}]

Basics

Installation

pip install slack-scim

User Management

https://api.slack.com/scim#users

import os
from slack_scim import Users, User
from slack_scim import SCIMClient, SCIMApiError

# `admin` scope required
token = os.environ["SLACK_ADMIN_TOKEN"]
client = SCIMClient(token=token)
try:
    search_result: Users = client.search_users(filter="restricted eq '1'", count=3)
    user_id = search_result.resources[0].id
    read_result: User = client.read_user(user_id)
except SCIMApiError as err:
    if err.status == 429:
        # handle rate limit errors
        pass

new_user: User = User.from_dict({
    "name": {
        "givenName": "Kazuhiro",
        "familyName": "Sera",
    },
    "emails": [{"value": "your-name@example.com"}],
    "userName": "seratch",
})
creation_result: User = client.create_user(new_user)
user_id = creation_result.id

patch_result: User = client.patch_user(user_id, {
    "name": {
        "givenName": "Kaz"
    }
})

patch_result.name.given_name = "K"
update_result: User = client.update_user(user_id, patch_result)

client.delete_user(user_id)

Group Management

https://api.slack.com/scim#groups

import os
from slack_scim import Groups, Group, GroupMember, SCIMClient, User

# `admin` scope required
token = os.environ["SLACK_ADMIN_TOKEN"]
client = SCIMClient(token=token)

display_name = "test-group-123"
new_group: Group = Group.from_dict({"displayName": display_name})
created_user: User = client.create_user(User.from_dict({
    "name": {
        "givenName": "Kazuhiro",
        "familyName": "Sera",
    },
    "emails": [{"value": "your-name@example.com"}],
    "userName": "seratch",
}))
new_group.members = [GroupMember.from_dict(created_user.to_dict())]
creation_result: Group = client.create_group(new_group)
if not creation_result:
    search_result: Groups = client.search_groups(filter=f"displayName eq {display_name}", count=1)
    creation_result: Group = search_result.resources[0]
group_id = creation_result.id

client.patch_group(group_id, {"displayName": display_name + "-2"})
patch_result: Group = client.read_group(group_id)

patch_result.display_name = display_name + "-3"
client.update_group(group_id, patch_result)
update_result = client.read_group(group_id)

client.delete_group(group_id)

License

The MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slack-scim-1.0.6.tar.gz (47.9 kB view details)

Uploaded Source

Built Distribution

slack_scim-1.0.6-py2.py3-none-any.whl (21.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file slack-scim-1.0.6.tar.gz.

File metadata

  • Download URL: slack-scim-1.0.6.tar.gz
  • Upload date:
  • Size: 47.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for slack-scim-1.0.6.tar.gz
Algorithm Hash digest
SHA256 cfb6f24e55e597d859411ff44afabe402d6b4ea7f1e01417d52af174d8c31613
MD5 95ea81bad8a6bef494446279d4a377d0
BLAKE2b-256 ac31dfe62b1f89c673a13b8ac1f2104a9bed8e4164c5dbd686324f9767774653

See more details on using hashes here.

File details

Details for the file slack_scim-1.0.6-py2.py3-none-any.whl.

File metadata

  • Download URL: slack_scim-1.0.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for slack_scim-1.0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5e2e3066ca9ba550251eab110ba0468ce135a593950bfbb817b4582c894bc6c0
MD5 e03dcf20bd4f4accccb7b7bce0b471c4
BLAKE2b-256 a25745aa6760c69b940017e0c55ccaeb30c3de981e842f7357eed057eb50045c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page