strongloop / loopback-component-passport

LoopBack passport integration to support third party logins and account linking
Other
139 stars 227 forks source link

Custom field mapping #244

Closed jackrvaughan closed 6 years ago

jackrvaughan commented 6 years ago

Description

Allows you to map certain fields from a third party provider (firstname for example) to a custom field in the user profile model. The current code only creates a new user with username, email, and password which is extremely limiting.

This update will allow you to add a profileMapping field to the provider object in providers.json that will map third party fields to custom user fields. Here is an example of what profileMapping could look like:

    "profileMapping":[
      {
        "providerField":"name.givenName",
        "userField":"firstName"
      },
      {
        "providerField":"name.familyName",
        "userField":"lastName"
      },
      {
        "providerField":"emails[0].value",
        "userField":"email"
      }
    ]

If profileMapping the profileToUser function will parse the third party profile json to get and set the appropriate field for the user model (or whatever local modal is being used).

Related issues

Checklist

slnode commented 6 years ago

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

jannyHou commented 6 years ago

@slnode test please

jannyHou commented 6 years ago

@jackrvaughan cool the existing tests pass, could you add a few new test case for the additional fields? Thanks.

jackrvaughan commented 6 years ago

@jannyHou I added a test case to ensure the custom field mapping works. Hope this is acceptable!

jackrvaughan commented 6 years ago

@jannyHou I noticed one check didn't pass (Commit Linter) because one of my commits was over 50 characters. Is that a problem?

raymondfeng commented 6 years ago

@jackrvaughan Thank you for the patch. Good idea.

The commit log has an issue:

**  Linting commit logs
**
**  1 problems found:
**    dd282d3 - changed description from 'profile' to 'field' mappi: First line should be 50 characters or less (saw 53)
**
raymondfeng commented 6 years ago

BTW, I think we already allow the mapping - https://github.com/strongloop/loopback-component-passport/blob/master/test/passport-configurator.test.js#L108.

Can you clarify?

jackrvaughan commented 6 years ago

@raymondfeng I believe that's only for LDAP?

I've gone back and fixed the commit. But now it's saying my PR is out of date - I'll work on rebasing it soon.