{"id":18298361,"url":"https://github.com/fusionauth/fusionauth-import-scripts","last_synced_at":"2025-04-05T13:33:23.955Z","repository":{"id":40344447,"uuid":"232433073","full_name":"FusionAuth/fusionauth-import-scripts","owner":"FusionAuth","description":"FusionAuth Import scripts for Auth0 and other examples","archived":false,"fork":false,"pushed_at":"2024-09-13T12:05:58.000Z","size":137,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-09-14T01:59:20.312Z","etag":null,"topics":["api","auth0","fusionauth","import","importer","scripts"],"latest_commit_sha":null,"homepage":"","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FusionAuth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-07T22:57:17.000Z","updated_at":"2024-09-13T12:06:02.000Z","dependencies_parsed_at":"2024-03-01T03:31:19.359Z","dependency_job_id":"27dc9b8b-8047-4c52-915a-2b41e3367397","html_url":"https://github.com/FusionAuth/fusionauth-import-scripts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-import-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-import-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-import-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-import-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FusionAuth","download_url":"https://codeload.github.com/FusionAuth/fusionauth-import-scripts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223192693,"owners_count":17103564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","auth0","fusionauth","import","importer","scripts"],"created_at":"2024-11-05T15:05:52.215Z","updated_at":"2024-11-05T15:05:53.029Z","avatar_url":"https://github.com/FusionAuth.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"## FusionAuth Import Scripts\n\nWe're building out import scripts for any and all third party Identity Providers. Feel free to submit a PR with your specific use of the Import API in whatever language you have.\n\n## Importers\n\n### Auth0\n\nGather the following:\n\n* Your Auth0 user data export file\n* Your Auth0 secrets export file\n* Your FusionAuth instance URL\n* A FusionAuth API key. This key must have at least the `/api/user/import` permission to import normal users, and the additional permissions of `/api/identity-provider/link` and `/api/user/search` to import social users.\n\nThe following gems are required to run this import script.\n\n```ruby\nrequire 'date'\nrequire 'json'\nrequire 'fusionauth/fusionauth_client'\nrequire 'optparse'\nrequire 'securerandom'\n```\n\nIf you are familiar with Ruby you can optionally build a build file, or simply install these gems prior to running the script. The `date`, `optparse`, `securerandom` and `json` gems are likely already available in your Ruby environment.\n\nYou can run `bundle install` if you have bundler installed, or you can install the gems manually: `sudo gem install fusionauth_client`, etc.\n\nFinally, execute the Import script:\n\n```bash\nruby ./import.rb -k fusionauth-api-key -u users.json -s secrets.json -f https://local.fusionauth.io -r 80492376-0ce2-4e9b-afa6-c093b78e57e5,3f282a4b-ef92-4c46-82d2-5eca8fa38293 \n\nYou can see all the options:\n\n```bash\nruby ./import.rb -h\n```\n\n#### Social providers\n\nThis script supports loading users from social providers such as LinkedIn or Google if you are running FusionAuth \u003e= 1.28. Otherwise it does not support importing such users.\n\nIf you are importing users with social providers, ensure that the Identity Provider is created in FusionAuth before importing the social users. See https://fusionauth.io/docs/v1/tech/identity-providers/ for more.\n\nYou can find additional social provider identity provider ids: https://github.com/FusionAuth/fusionauth-java-client/blob/master/src/main/java/io/fusionauth/domain/provider/IdentityProviderType.java and you may need to update the `idp_identifiers_to_auth0_type` variable with additional mappings between what Auth0 calls a social provider and the Id FusionAuth user. \n\n### CSV\n\nThe example [CSV import script](./csv/import.rb) provides a starting point for importing users from a CSV into FusionAuth.  This example maps the CSV fields by header from [the example CSV](./csv/example_users.csv) onto FusionAuth users within the `map_user` function.  You will likely need to update `map_user` to map the fields from your CSV accordingly.\n\nTo begin, modify the section that begins with `BEGIN Modify these variables for your Import` with values that match your FusionAuth environment.\n\nThe following gems are required to run this import script.\n\n```ruby\nrequire 'date'\nrequire 'csv'\nrequire 'fusionauth/fusionauth_client'\n```\n\nIf you are familiar with Ruby you can optionally build a build file, or simply install these gems prior to running the script. The `date` gem is likely already available in your Ruby environment.\n\n```bash\nsudo gem install csv\nsudo gem install fusionauth_client\n```\n\nFinally, execute the Import script.\n\n```bash\nruby ./import.rb\n```\n\n### Keycloak\n\nGather the following:\n\n* Your Keycloak database credentials\n* The Id of each realm you want to import.\n* Your FusionAuth instance URL\n* A FusionAuth API key. This key must have at least the `/api/user/import` permission to import users.\n\n#### Install the plugin\n\nKeycloak by default uses a password hashing algorithm that doesn't ship with FusionAuth. However, there is an example password hashing plugin available here:\n\nInstall the plugin. By default, it installs the plugin with the name `example-keycloak`. You can use a different name, but if you do, you'll need to modify the `map_hashing_algorithm` method in the import script. \n\nHere are the installation instructions: https://fusionauth.io/docs/v1/tech/plugins/writing-a-plugin/#install-the-plugin\n\nIf you used a different hashing algorithm, build a plugin that uses that algorithm and install it.\n\n#### Retrieve the user data\n\nRun the SQL query in `keycloak/keycloak-export.sql` to retrieve the needed data for each realm.\n\nEdit that file to replace `RealmID` with the value of the realm. You can find that in the admin screen, it is the `Name` field of the realm. You'll want a separate output file for each realm. Realms in Keycloak map to Tenants in FusionAuth.\n\nOutput the results of this query to a CSV file. How you do so depends on the database. Assuming the SQL above is stored in `keycloak-export.sql`, the database username is `USER`, the database password is `password`, and the keycloak database is `keycloak`, the export command might be: \n\n* mysql: `cat keycloak-export.sql | mysql -u USER -ppassword keycloak| sed 's/\\t/,/g' \u003e out.csv`. You may have to remove the header line.\n* postgresql: `psql -W -h localhost -p5433 -U USER -d fusionauth -c \"Copy (CONTENTS OF SQL FILE) To STDOUT With CSV HEADER DELIMITER ',';\" \u003e out.csv`\n\nIn any event, you'll end up with a file that looks like this:\n\n```\nFIRST_NAME,LAST_NAME,EMAIL,USERNAME,EMAIL_VERIFIED,ID,SECRET_DATA,CREDENTIAL_DATA,CREATED_TIMESTAMP,REALM_ID\nTest,Example,test@example.com,test,\\0,f35a58e2-0247-4c38-aa39-93405e09c677,{\"value\":\"T6S/56cQy0ahQKohXe61aMOhvFr/PHEPfQbILKMLZKrdfOSo8wc+S6HCYomSJwTgYmdPy2gKh+oQW9UbeCmEwQ==\",\"salt\":\"eYcTxcZhBV+GU9BQRt8Ypw==\",\"additionalParameters\":{}},{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\",\"additionalParameters\":{}},1634670076567,Test\nTest,Example2,test2@example.com,test2,\u0001,1709a278-12a5-4126-9542-02f6809a349e,{\"value\":\"LjFqvhPuUHJdQvWIwVQfqxjeujAWqG/DVQRFoOv62/cTznl9ob4jwWwY6i1RrwGviu5iNPU5VIp03SxDyetyfw==\",\"salt\":\"jVqbuA9k2Mlo37OWXBMKLw==\",\"additionalParameters\":{}},{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\",\"additionalParameters\":{}},1634670197972,Test\n```\n\nYou can tweak this SQL file to, for example, only retrieve enabled users or those created after a certain date. The main tables you are interested in are `USER_ENTITY` and `CREDENTIAL`.\n\n#### Import the data\n\nThe following gems are required to run this import script.\n\n```ruby\nrequire 'date'\nrequire 'json'\nrequire 'fusionauth/fusionauth_client'\nrequire 'optparse'\n```\n\nIf you are familiar with Ruby you can optionally build a build file, or simply install these gems prior to running the script. The `date`, `optparse` and `json` gems are likely already available in your Ruby environment.\n\nYou can run `bundle install` if you have bundler installed, or you can install the gems manually: `sudo gem install fusionauth_client`, etc.\n\nFinally, execute the import script. This command imports into an instance running at local.fusionauth.io, into the `80492376-0ce2-4e9b-afa6-c093b78e57e5` tenant, from the `import.csv` file:\n\n```bash\nruby ./import.rb -u import.csv -f https://local.fusionauth.io -t 80492376-0ce2-4e9b-afa6-c093b78e57e5 -k apikeyapikey\n\nYou can see all the options:\n\n```bash\nruby ./import.rb -h\n```\n\n### Firebase\n\nPlease see https://fusionauth.io/docs/v1/tech/migration-guide/firebase for full instructions.\n\n### Azure AD B2C\n\nPlease see https://fusionauth.io/docs/v1/tech/migration-guide/azureadb2c for full instructions.\n\n### Duende Identity Server\n\nPlease see https://fusionauth.io/docs/v1/tech/migration-guide/duende for full instructions.\n\n### Amazon Cognito\n\nPlease see https://fusionauth.io/docs/v1/tech/migration-guide/cognito for full instructions.\n\n### Stytch \n\nPlease see https://fusionauth.io/docs/lifecycle/migrate-users/provider-specific/stytch for full instructions.\n\n### Custom Authentication System\n\nPlease see https://fusionauth.io/docs/lifecycle/migrate-users/genericmigration for full instructions.\n\n### Ping Identity\n\nPlease see https://fusionauth.io/docs/lifecycle/migrate-users/provider-specific/pingone for full instructions\n\n### WordPress\n\nPlease see https://fusionauth.io/docs/lifecycle/migrate-users/provider-specific/wordpress for full instructions.\n\n### Frontegg\n\nPlease see https://fusionauth.io/docs/lifecycle/migrate-users/provider-specific/frontegg for full instructions.\n\n### Generate Test Users\n\nThis script will use the Import API to bulk create users for load testing FusionAuth.\n\nThe following gems are required to run this import script.\n\n```ruby\nrequire 'rubygems'\nrequire 'json'\nrequire 'net/http'\nrequire 'getoptlong'\nrequire 'openssl'\n```\n\nMake sure you set up an application with a `user` role into which to import users. The FusionAuth URL must have no trailing slash. The API key must have at least the `POST` permissions on the `/api/user/import` endpoint. Users will be imported with a password of `password`.\n\nExample usage:\n\nImport 1 million users\n```bash\nruby generate_import.rb --apiKey \u003cAPI Key\u003e --applicationId \u003cApplication Id\u003e --tenantId \u003cTenantId\u003e --url http://localhost:9011 --total 1000000 \n```\n\nGenerate 100,000 users.\n```bash\nruby generate_import.rb --apiKey \u003cAPI Key\u003e --applicationId \u003cApplication Id\u003e --tenantId \u003cTenantId\u003e --url http://localhost:9011 --total 100000 \n```\n\nGenerate 100,000 users with an offset of 100,000. This would allow you to import an additional 100k users after the first 100k.\n```bash\nruby generate_import.rb --apiKey \u003cAPI Key\u003e --applicationId \u003cApplication Id\u003e --tenantId \u003cTenantId\u003e --url http://localhost:9011 --total 100000 --ofset 100000\n```\n\n### Generate Applications\n\nThis script will use the Application API to create applications.\n\nThe following gems are required to run this import script.\n\n```ruby\nrequire 'rubygems'\nrequire 'json'\nrequire 'net/http'\nrequire 'getoptlong'\nrequire 'openssl'\n```\n\nExample usage:\nGenerate 3,000 applications\n```bash\nruby generate_applications.rb --apiKey \u003cAPI Key\u003e --tenantId \u003cTenantId\u003e --url http://localhost:9011 --total 3000 \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusionauth%2Ffusionauth-import-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffusionauth%2Ffusionauth-import-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusionauth%2Ffusionauth-import-scripts/lists"}