Coder Social home page Coder Social logo

python-slack-scim's Introduction

python-slack-scim's People

Contributors

jlumbroso avatar seratch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

python-slack-scim's Issues

Problem Instantiating A Group from Dict with Members

Hi, I've been trying this code to create a SCIM Group from existing Slack Users

import logging
import os

import slack_scim
from slack.web.classes.interactions import IDNamePair
from slack_scim import Group, GroupMember

logging.basicConfig(level=logging.DEBUG)
client = slack_scim.SCIMClient(token=os.environ["SLACK_ADMIN_TOKEN"])

users = [IDNamePair('<id>', 'William'), IDNamePair('<id>', 'Peter')]
members = [GroupMember.from_dict({'value': user.id}) for user in users]
display_name = 'My Test Group'
new_group = Group.from_dict({'displayName': display_name, 'members': members})

and I've been getting this exception trace back from trying to create the group from dict

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2020.1.3\plugins\python\helpers\pydev\pydevd.py", line 1448, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2020.1.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/William Fox/AppData/Roaming/JetBrains/PyCharm2020.2/scratches/slack-scim-tests.py", line 14, in <module>
    new_group = Group.from_dict({'displayName': display_name, 'members': members})
  File "C:\Users\William Fox\PycharmProjects\slack-channel-restrictor\venv\lib\site-packages\slack_scim\v1\group.py", line 107, in from_dict
    members = from_union([lambda x: from_list(Member.from_dict, x), from_none], obj.get("members"))
  File "C:\Users\William Fox\PycharmProjects\slack-channel-restrictor\venv\lib\site-packages\slack_scim\v1\group.py", line 31, in from_union
    assert False
AssertionError

However if I instead make the Group with just the displayName and then update members later I'm able to create the group successfully

new_group = Group.from_dict({'displayName': display_name})
new_group.members = members
result = client.create_group(new_group)

I'm unsure if this is a bug or my usage is wrong

Python Version 3.7.7

read_group does not return members id and display name

Hi,

I was trying to use the library for read_group method however the response object does not contain member object attributes.
All seem to be none.

client = slack_scim.SCIMClient(xoxp-XXXXXXXXXX)
response = client.read_group('XXXXXXXXX')
response.__dict__
{'display_name': 'LDAP_slack-xxxxxxxx', 'id': 'XXXXXXXXX', 'members': [<slack_scim.v1.group.Member object at 0x1065b7730>, <slack_scim.v1.group.Member object at 0x1065b7670>, <slack_scim.v1.group.Member object at 0x1065b76a0>, <slack_scim.v1.group.Member object at 0x1065b7850>, <slack_scim.v1.group.Member object at 0x1065b77c0>, <slack_scim.v1.group.Member object at 0x1065b7820>, <slack_scim.v1.group.Member object at 0x1065b77f0>, <slack_scim.v1.group.Member object at 0x1065b78b0>, <slack_scim.v1.group.Member object at 0x1065b78e0>, <slack_scim.v1.group.Member object at 0x1065b7940>, <slack_scim.v1.group.Member object at 0x1065b7970>, <slack_scim.v1.group.Member object at 0x1065b7910>], 'meta': <slack_scim.v1.group.Meta object at 0x106594fd0>, 'schemas': ['urn:scim:schemas:core:1.0']}
res.members[0].__dict__
{'active': None, 'display_name': None, 'external_id': None, 'id': None, 'locale': None, 'meta': None, 'name': None, 'nick_name': None, 'password': None, 'preferred_language': None, 'profile_url': None, 'schemas': None, 'timezone': None, 'title': None, 'urn_scim_schemas_extension_enterprise_10': None, 'user_name': None, 'user_type': None}

The expected behaviour is that member's id and display_name should be populated as it was received in the response.

DEBUG:slack_scim.v1.client:*** SCIM API Response ***
GET https://api.slack.com/scim/v1/Groups/XXXXXX
200 OK
date: Thu, 30 Jul 2020 09:57:07 GMT
server: Apache
strict-transport-security: max-age=31536000; includeSubDomains; preload
referrer-policy: no-referrer
x-slack-backend: r
vary: Accept-Encoding
x-xss-protection: 0
x-frame-options: SAMEORIGIN
connection: close
transfer-encoding: chunked
content-type: application/json; charset=utf-8

{"schemas":["urn:scim:schemas:core:1.0"],"id":"XXXXXXX","displayName":"xxxxxxxx","members":[{"value":"XXXXX","display":"Michael Jackson"}],"meta":{"created":"2019-03-18T09:05:06-07:00","location":"https:\/\/api.slack.com\/scim\/v1\/Groups\/XXXXXX"}}

Updating profile photo does not work

Hello @seratch: I have not been able to update the profile photo, even with a photo that is supposed to be exactly the right size.

The PATCH doesn't fail, it appears successful, but the image is still the anonymous gravatar. The only documentation I could track about this, and it doesn't not provide any clarifying additional information.

import slack_scim

client = slack_scim.SCIMClient(token="<token>")

def find_user(email):
    for i in range(len(users.resources)):
        if users.resources[i].emails[0].value != email:
            continue
        return users.resources[i]

def find_user_id(email):
    return find_user(email).id

user_id = find_user_id("[email protected]")

patch_result = client.patch_user(user_id, {
    "photos": [{
            "value": "https://wallpapercave.com/wp/wp4471355.jpg",
            "primary": True
        }
    ]})

Include instructions on getting token in `README.md`

This is a wonderful library!

The token that the README.md suggests using, seems to be described as a "Legacy Token" by the official Slack documentation. Other instructions are not very straightforward.

I would link directly to instructions within the README.md:

As explained in the official Slack SCIM API documentation, the easiest way to obtain a valid token for the purposes of SCIM provisioning are:

  1. As a Workspace/Organization Owner, create a new app for your workspace (see here for the documentation).
  2. Add the admin OAuth scope to the "User Token Scopes" section.
  3. Install the app to your workspace (see here for the documentation).
  4. Use the generated token (if you are provided with multiple tokens, use the "OAuth Access Token" not the "Bot User OAuth Access Token").

Note that you can easily reinstall your app with different permissions if it turns out you did not select all the necessary permissions.

Indeed, one of the most challenging things for users of an SDK is figuring out how to obtain the right credentials. This is made more difficult by Slack's multiple changes of authentication method, and at times inconsistent terminology.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.