zorn-v / nextcloud-social-login

GNU Affero General Public License v3.0
199 stars 138 forks source link

using zitadel with nextcloud-social-login via occ commands #434

Closed jessebot closed 11 months ago

jessebot commented 11 months ago

Thanks for working on this app! I am excited to use it :)

I setup an OIDC app for nextcloud using zitadel's guide here and I wanted to write a little script to be able to configure the provider in the nextcloud social login app, so I tried the occ command listed in the README of this repo:

php occ config:app:set sociallogin custom_providers --value='{"custom_oidc": [{"name": "ZITADEL", "title": "ZITADEL", "authorizeUrl": "https://zitadel.mydomain.online/oauth/v2/authorize", "tokenUrl": "https://zitadel.mydomain.online/oauth/v2/token", "userInfoUrl": "https://zitadel.mydomain.online/oauth/v2/userinfo", "logoutUrl": "", "clientId": "546543653465436443565@myproj", "clientSecret": "gZ8JS3veB87PjfsdjakvgbjagajogahysqZVDFAgdagGLzY", "scope": "openid", "groupsClaim": "groups", "style": "zitadel", "defaultGroup": "nextcloud_users"}]}'

Here's the inline json made a little easier to read:

{"custom_oidc": [{
    "name": "ZITADEL",
    "title": "ZITADEL", 
    "authorizeUrl": "https://zitadel.mydomain.online/oauth/v2/authorize", 
    "tokenUrl": "https://zitadel.mydomain.online/oauth/v2/token", 
    "userInfoUrl": "https://zitadel.mydomain.online/oauth/v2/userinfo", 
    "logoutUrl": "", 
    "clientId": "546543653465436443565@myproj", 
    "clientSecret": "gZ8JS3veB87PjfsdjakvgbjagajogahysqZVDFAgdagGLzY", 
    "scope": "openid",
    "groupsClaim": "groups", 
    "style": "zitadel", 
    "defaultGroup": "nextcloud_users"}]
}

When I check via the occ command suggested in the readme, I do indeed get back the correct info:

$ php occ config:app:get sociallogin custom_providers
{custom_oidc: [{name: ZITADEL,  title: ZITADEL, authorizeUrl: https://zitadel...

I truncated the get response above, just so I didn't have to anonymize more data, but all the same info is returned as I put in, which is good, but when I check the web interface under administration settings > social login, I don't see anything and there's not no special buttons or anything new when I logout and check the login page.

Am I missing something? Are there additional commands I need to run to make nextcloud see the updates I made via the occ commands? Are there any other commands I can run to check into the status here?

jessebot commented 11 months ago

oop, no it was my own issue escaping quotes for the json blob via a kubectl exec command.

I fixed it with the following in my python script:

        oidc_json = dumps({
                "custom_oidc": [{
                    "name": "ZITADEL",
                    "title": "ZITADEL",
                    "authorizeUrl": f"https://{zitadel_host}/oauth/v2/authorize",
                    "tokenUrl": f"https://{zitadel_host}/oauth/v2/token",
                    "userInfoUrl": f"https://{zitadel_host}/oauth/v2/userinfo",
                    "logoutUrl": "",
                    "clientId": client_id,
                    "clientSecret": client_secret,
                    "scope": "openid",
                    "groupsClaim": "groups",
                    "style": "zitadel",
                    "defaultGroup": "nextcloud_users"
                    }]
                }).replace('"', '\\"')

then I was able to use that in a command like kubectl exec -n nextcloud nextcloud-pod -c nextcloud -- su -s /bin/bash www-data -c "php occ config:app:set sociallogin custom_providers --value='{oidc_json}'" fed to subprocess.Popen with args shell=True and universal_newlines=True which is painful but all is well :D

Good luck anyone else who attempts to use kubectl via python :)