# Discourse\_api sync\_sso custom\_fields führt im Payload zu "custom.custom.\<field\>"

**URL:** https://meta.discourse.org/t/discourse-api-sync-sso-custom-fields-results-in-custom-custom-field-in-payload/140127
**Category:** Bug
**Created:** [30. Januar 2020 um 00:18 UTC](https://meta.discourse.org/t/discourse-api-sync-sso-custom-fields-results-in-custom-custom-field-in-payload/140127 "2020-01-30T00:18:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vkozyrev](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vkozyrev/32/167391_2.png) [@vkozyrev](https://meta.discourse.org/u/vkozyrev)
#### Post date: [30. Januar 2020 um 00:18 UTC](https://meta.discourse.org/t/discourse-api-sync-sso-custom-fields-results-in-custom-custom-field-in-payload/140127/1 "2020-01-30T00:18:09Z")

</div>

> <https://github.com/discourse/discourse_api/pull/190>
>
> \* \`DiscourseApi::SingleSignOn.custom\_fields\` adds its own \`custom.\`	prefix befor…e sending the payload
> \* \`sync\_sso\` expected the	params to have the prefix in the params	
> \* This results in \`custom.custom.field\` in the payload
> 
> Also added some overkill tests

`DiscourseApi::SingleSignOn` erwartet, dass benutzerdefinierte Attribute wie folgt zugewiesen werden:

```plaintext
sso.custom_fields['field_1'] = 'value'

# was zu einem `custom.field_1`-Schlüssel im Payload führt

```

`DiscourseApi::API::SSO.sync_sso()` erwartet, dass die Parameter wie folgt aufgebaut sind:

```plaintext
{ 'custom.field_1' => 'value' }

```

Es wird jedoch das `custom.`-Präfix an `sso.custom_fields` übergeben.  
Dies führt dazu, dass der Payload folgendes enthält:

```plaintext
custom.custom.field_1

```

Außerdem wurden einige überflüssige Tests für `sync_sso` hinzugefügt.

---

<div class="post-metadata">

### Author: ![vkozyrev](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vkozyrev/32/167391_2.png) [@vkozyrev](https://meta.discourse.org/u/vkozyrev)
#### Post date: [30. Januar 2020 um 00:24 UTC](https://meta.discourse.org/t/discourse-api-sync-sso-custom-fields-results-in-custom-custom-field-in-payload/140127/2 "2020-01-30T00:24:02Z")

</div>

Das wäre meiner Meinung nach viel einfacher gewesen, aber ich möchte keine bestehenden Apps brechen 😬. Überlassen Sie die Generierung der SSO-Instanz dem Benutzer.

```plaintext
# frozen_string_literal: true
module DiscourseApi
  module API
    module SSO
      def sync_sso(sso)
        post("/admin/users/sync_sso", sso.payload)
      end
    end
  end
end

```

Vielleicht mache ich morgen etwas Ähnliches (aber etwas sauberer):

```plaintext
# frozen_string_literal: true
module DiscourseApi
  module API
    module SSO
      def sync_sso(params)
        if params.instance_of?(DiscourseApi::SingleSignOn)
          post("/admin/users/sync_sso", sso.payload) 
        elsif params.instance_of?(Hash)
          .... identisch mit der aktuellen Version
        end
      end
    end
  end
end

```

Was haltet ihr davon? Mein App soll idealerweise eine einzige Funktion haben, die `DiscourseApi::SingleSignOn` generiert, und ich könnte sie dann an `sso_login` oder `sync_sso` übergeben.

Oder die Parameter könnten so definiert werden:

```plaintext
{
  sso_secret: ...
  name: ...
  custom_fields: {
    field_1: ...
  }
}

```

Was ebenfalls bestehende Apps brechen würde.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [5. August 2020 um 13:42 UTC](https://meta.discourse.org/t/discourse-api-sync-sso-custom-fields-results-in-custom-custom-field-in-payload/140127/3 "2020-08-05T13:42:21Z")

</div>

Dies wurde letzten Monat behoben:

> <https://github.com/discourse/discourse_api/commit/9587ed754a3f7164d66defe339e48a174bb2f1e7>
>
> \* DiscourseApi::SingleSignOn.custom\_fields adds its own \`custom.\` prefix before …sending the payload
> \`sync\_sso\` expected the params to have the prefix in the params
> This results in \`custom.custom.field\` in the payload
> 
> \* \* I make this look good (•\_•) / ( •\_•)\>⌐■-■ / (⌐■\_■)
> 
> \* - Readme.md
> 
> \* - Style
> 
> \* - Use #sub instead of #gsub. Remove only first instance of \`custom.\`
> 
> \* - Updated spec
> 
> \* - More spec updates
> 
> \* - SingleSignOn.unsigned\_payload no longer prepends its own \`custom.\`
> 
> \* - WIP
> 
> \* \* New parse\_hash init method for DiscourseApi::SingleSignOn
> \* Updated sync\_sso()
> \* custom\_fields params input changed
> 
> \* - Fixed rubocop
> 
> \* - Readme

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [5. August 2020 um 13:42 UTC](https://meta.discourse.org/t/discourse-api-sync-sso-custom-fields-results-in-custom-custom-field-in-payload/140127/4 "2020-08-05T13:42:24Z")

</div>


