Defining a new user password through Keycloak REST API - keycloak

I am trying to create a new user via the REST API, and I'm sending this POST
POST /admin/realms/myrealm/users
Headers:
Authorization: Bearer (generated token, this part is OK)
Content-Type: application/json
Body:
{
"username": "rahul",
"enabled": true,
"totp": false,
"emailVerified": false,
"firstName": "rahul",
"lastName": "borse",
"email": "rahulborse#yahoo.com",
"credentials": [
{
"type": "password",
"value": "rahul"
}
]
}
The user is created normally, but the password doesn't work, when I try to
login it claims I have invalid credentials.

Try to add mapping "temporary": false to credentials:
{
"username": "rahul",
"enabled": true,
"totp": false,
"emailVerified": false,
"firstName": "rahul",
"lastName": "borse",
"email": "rahulborse#yahoo.com",
"credentials": [
{
"type": "password",
"value": "rahul",
"temporary": false
}
]
}

Related

Send mail from Mailhog to Gmail but gmail can't receive mail

I'm try to use api in mailhog
Get /api/v1/messages
[
{
"ID": "ZOif6IQhqZgViFi2HO4e8KBSJBAzlwwJ-92rCBccNU8=#mailhog.example",
"From": {
"Relays": null,
"Mailbox": "developer-send-mail",
"Domain": "gmail.com",
"Params": ""
},
"To": [
{
"Relays": null,
"Mailbox": "developer-recv-mail",
"Domain": "gmail.com",
"Params": ""
}
],
"Content": {
"Headers": {
"Message-ID": [
"ZOif6IQhqZgViFi2HO4e8KBSJBAzlwwJ-92rCBccNU8=#mailhog.example"
],
"Received": [
"from smtp.gmail.com by mailhog.example (MailHog)\r\n id ZOif6IQhqZgViFi2HO4e8KBSJBAzlwwJ-92rCBccNU8=#mailhog.example; Mon, 22 Nov 2021 18:30:16 +0000"
],
"Return-Path": [
"<developer-send-mail#gmail.com>"
]
},
"Body": "test my message\r\nnew1\r\nmulti line",
"Size": 33,
"MIME": null
},
"Created": "2021-11-22T18:30:16.822037969Z",
"MIME": null,
"Raw": {
"From": "developer-send-mail#gmail.com",
"To": [
"developer-recv-mail#gmail.com"
],
"Data": "test my nessaje\r\nnew1\r\nmulti line",
"Helo": "smtp.gmail.com"
}
},
]
and I
Post /api/v1/messages/ZOif6IQhqZgViFi2HO4e8KBSJBAzlwwJ-92rCBccNU8=#mailhog.example/release
Body
{
"Host": "smtp.gmail.com",
"Port": "587",
"Username": "developer-send-mail#gmail.com",
"Password": "MyMailPassword",
"Mechanism": "PLAIN",
"Email": "developer-send-mail#gmail.com"
}
Response code: 200
but in gmail developer-recv-mail#gmail.com can't receive this email
In your post value for release endpoint, you specify an Email value of developer-send-mail#gmail.com. Since this value is the recipient, I believe this should be developer-recv-mail#gmail.com from the sound of it?
https://github.com/mailhog/MailHog/blob/master/docs/APIv1.md#post-apiv1messages-message_id-release

Azure DevOps REST API to create a release definition

I'm trying to create a release definition by using Azure DevOps REST API. I've created a json file which has configuration details for the request. I'm getting the below error, while creating the release definition.
{
"$id": "1",
"innerException": null,
"message": "Workflow of deploy job 'Run on the agent' in release pipeline stage 'development' is invalid. Add valid tasks and try again.",
"typeName": "Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data",
"typeKey": "InvalidRequestException",
"errorCode": 0,
"eventId": 3000
}
I'm using the below request body to create a new release definition in Azure cloud.
{
"name": "myreleasedefn1",
"artifacts": [{
"type": "DockerHub",
"alias": "_dockerusername_mydockerimage",
"definitionReference": {
"connection": {
"id": "dd986f4a-123k-45d5-b8e6-fc4fds23rce",
"name": "dockerservice"
},
"defaultVersionType": {
"id": "selectDuringReleaseCreationType",
"name": "Specify at the time of release creation"
},
"definition": {
"id": "dockerusername/mydockerimage",
"name": "dockerusername/mydockerimage"
},
"namespaces": {
"id": "dockerusername",
"name": "dockerusername"
}
},
"isPrimary": true,
"isRetained": false
}],
"releaseNameFormat": "Release-$(rev:r)",
"environments": [{
"name": "development",
"rank": 1,
"retentionPolicy": {
"daysToKeep": 30,
"releasesToKeep": 3,
"retainBuild": true
},
"preDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": true,
"isNotificationOn": false,
"id": 10
}
],
"approvalOptions": {
"requiredApproverCount": null,
"releaseCreatorCanBeApprover": false,
"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
"enforceIdentityRevalidation": false,
"timeoutInMinutes": 0,
"executionOrder": "beforeGates"
}
},
"postDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": true,
"isNotificationOn": false,
"id": 12
}
],
"approvalOptions": {
"requiredApproverCount": null,
"releaseCreatorCanBeApprover": false,
"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
"enforceIdentityRevalidation": false,
"timeoutInMinutes": 0,
"executionOrder": "afterSuccessfulGates"
}
},
"deployPhases": [{
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": "none"
},
"agentSpecification": {
"identifier": "ubuntu-16.04"
},
"skipArtifactsDownload": false,
"artifactsDownloadInput": {
"downloadInputs": []
},
"queueId": 9,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {}
},
"rank": 1,
"phaseType": "agentBasedDeployment",
"name": "Run on the agent",
"workflowTasks": [{
"version": "4.*",
"name": "Deploy Azure App Service",
"refName": "",
"enabled": true,
"alwaysRun": false,
"continueOnError": false,
"timeoutInMinutes": 0,
"overrideInputs": {},
"condition": "succeeded()",
"inputs": {
"ConnectionType": "AzureRM",
"WebAppKind": "webAppContainer",
"WebAppName": "azureappservice1",
"DeployToSlotOrASEFlag": "false",
"ResourceGroupName": "",
"SlotName": "production",
"DockerNamespace": "dockerusername",
"DockerRepository": "mydockerimage",
"DockerImageTag": "10"
}
}]
}]
}]
}
It would be very helpful if you share an example template for the same request.
Please help!!!
Azure DevOps REST API to create a release definition
According to the error message:
"Workflow of deploy job 'Run on the agent' in release pipeline stage 'development' is invalid.
We could to know the task Deploy Azure App Service in the workflowTasks is invalid, we need to provide the correct request body for that task.
As I answered your previous post How to create new build pipeline using Azure DevOps REST API, this is very difficult and error-prone, if we add a huge request body completely manually. Usually, we use REST API Definitions - Get to get the Response Body from the similar release pipeline, then we update the corresponding properties by modifying the Response Body.
As test, I add the task Deploy Azure App Service in my release pipeline, then I use the REST API:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.0
to get the Response Body:
"workflowTasks": [
{
"environment": {},
"taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1",
"version": "4.*",
"name": "Azure App Service Deploy: xxxx",
"refName": "",
"enabled": true,
"alwaysRun": false,
"continueOnError": false,
"timeoutInMinutes": 0,
"definitionType": "task",
"overrideInputs": {},
"condition": "succeeded()",
"inputs": {
"ConnectionType": "AzureRM",
"ConnectedServiceName": "xxxxx",
"PublishProfilePath": "$(System.DefaultWorkingDirectory)/**/*.pubxml",
"PublishProfilePassword": "",
"WebAppKind": "webApp",
"WebAppName": "xxxx",
"DeployToSlotOrASEFlag": "false",
"ResourceGroupName": "",
"SlotName": "production",
"DockerNamespace": "",
"DockerRepository": "",
"DockerImageTag": "",
"VirtualApplication": "",
"Package": "$(System.DefaultWorkingDirectory)/**/*.zip",
"RuntimeStack": "",
"RuntimeStackFunction": "",
"StartupCommand": "",
"ScriptType": "",
"InlineScript": ":: You can provide your deployment commands here. One command per line.",
"ScriptPath": "",
"WebConfigParameters": "",
"AppSettings": "",
"ConfigurationSettings": "",
"UseWebDeploy": "false",
"DeploymentType": "webDeploy",
"TakeAppOfflineFlag": "true",
"SetParametersFile": "",
"RemoveAdditionalFilesFlag": "false",
"ExcludeFilesFromAppDataFlag": "true",
"AdditionalArguments": "-retryAttempts:6 -retryInterval:10000",
"RenameFilesFlag": "true",
"XmlTransformation": "false",
"XmlVariableSubstitution": "false",
"JSONFiles": ""
}
}
]
You could use this response body, and overwrite those properties you want to change.
Where can I get taskId in Azure portal?
You could check the source code of the task from Github,it is generally on the first line of task.json. Or you can use REST API/F12 to get it.
Can we use 'AzureContainerRegistry' as artifact type in the request
body?
The answer should be yes (not test it by a sample). You could add following request body in the body:
"artifacts": [
{
"sourceId": "xxxxxxxxxxxxxxx",
"type": "AzureContainerRepository",
"alias": "xxx",
"definitionReference": {
"connection": {
"id": "xxxxxx",
"name": "xxxx"
},
"defaultVersionType": {
"id": "latestType",
"name": "Latest"
},
"definition": {
"id": "xx",
"name": "xx"
},
"registryurl": {
"id": "22",
"name": "22"
},
"resourcegroup": {
"id": "xx",
"name": "xx"
}
},
"isPrimary": true,
"isRetained": false
}
],
Hope this helps.
I can help here. In workflowTasks You need to include the "taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1" which is id of the AzureRmWebAppDeploymentV4.
"workflowTasks": [
{
"taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1",
"version": "4.*",
"name": "Deploy Azure App Service",
"refName": "",
"enabled": true,
"alwaysRun": false,
"continueOnError": false,
"timeoutInMinutes": 0,
"definitionType": null,
"overrideInputs": {},
"condition": "succeeded()",
"inputs": {
"ConnectionType": "AzureRM",
"WebAppKind": "webAppContainer",
"WebAppName": "azureappservice1",
"DeployToSlotOrASEFlag": "false",
"ResourceGroupName": "",
"SlotName": "production",
"DockerNamespace": "dockerusername",
"DockerRepository": "mydockerimage",
"DockerImageTag": "10"
}
Once I added that I was able to create the release definition with your request body.

json-schema-faker generate new data

I am new to using json-server and json-schema-faker. I can get it to generate records but when I post to the endpoint, the only thing that it posts to the database is an object with id, why doesn't it have the other fields (i.e name, pro1, pro2 etc). Can anyone help?
Below is my schema:
export const schema = {
"type": "object",
"properties": {
"tests": {
"type": "array",
"minItems": 1,
"maxItems": 6,
"items": {
"type": "object",
"properties": {
"id": {
"type": "number",
"unique": true,
"minimum": 1
},
"name": {
"type": "string"
},
"pro1": {
"type": "integer",
"minimum": 0,
"maximum": 100
},
"pro2": {
"format": "date-time",
"type": "string"
},
"pro3": {
"type": "boolean"
},
"pro4": {
"type": "integer",
"minimum": 1,
"maximum": 10
},
"pro5": {
"type": "integer",
"minimum": 1,
"maximum": 10
}
},
"required": ["id", "name", "pro1", "pro2", "pro3", "pro4", "pro5"]
}
}
},
"required": ["tests"]
};
And my generate file:
import jsf from 'json-schema-faker';
import {schema} from './mockDataSchema';
import fs from 'fs';
import chalk from 'chalk';
const json = JSON.stringify(jsf(schema));
fs.writeFile("./src/api/db.json", json, function(err){
if (err){
return console.log(chalk.red(err));
}else{
return console.log(chalk.green("Mock Data Generated"));
}
});
In Header-s part of POST-request, must have header : "Content-Type: application/json"
In Body part ('raw' object) of POST-request, write object, that have to be post-ed to server like this :
{
"id": 1,
"name": "John Doe",
"email": "John.Doe#mailserver.com"
}
For example : with POSTMAN (http client application),
the POST request is like this :
POST /users HTTP/1.1
Host: 127.0.0.1:3001
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: some postman token
{
"id": 1,
"name": "John Doe",
"email": "John.Doe#mailserver.com"
}

Typical ormconfig.json file for Google Cloud SQL?

I have been trying for hours. What should be the ormconfig.json file for Google Cloud SQL working with TypeORM? I managed to get it working with the IP of the DB locally (with mysql workbench and Google cloud proxy and whitelisting my ip) but I don't know what the connection details should be for app engine.
{
"name": "default",
"type": "mysql",
"host": "/cloudsql/[project:region:instance]",
"port": "3306",
"username": "root",
"password": "xxxx",
"database": "yyy",
"synchronize": true,
"logging": false,
"entities": [
"modules/**/*.entity.js"
]
}
or
{
"name": "default",
"type": "mysql",
"extra": {
"socketPath": "/cloudsql/[project:region:instance]"
},
"username": "root",
"password": "xxxx",
"database": "yyy",
"synchronize": true,
"logging": false,
"entities": [
"modules/**/*.entity.js"
]
}
or anything else?
Thanks a lot!
For those interested, here is the solution:
{
"name": "default",
"type": "mysql",
"extra": {
"socketPath": "/cloudsql/[project:region:instance]"
},
"username": "root",
"password": "xxxx",
"database": "yyy",
"synchronize": true,
"logging": false,
"entities": [
"dist/**/*.entity.js"
]
}
Note that I also changed the entities path
It didn't worked for me until I added the "cloud_sql" path also the the "host":
{
"name": "default",
"host": "/cloudsql/[project:region:instance]",
"type": "mysql",
"extra": {
"socketPath": "/cloudsql/[project:region:instance]"
},
"username": "root",
"password": "xxxx",
"database": "yyy",
"synchronize": true,
"logging": false,
"entities": [
"dist/**/*.entity.js"
]
}

Visual Studio Code SFTP to multiple servers

In PhpStorm, there is a way to configure multiple SFTP endpoints and chose which server you want to upload to. I'm looking for this functionality in Visual Studio Code. I have installed SFTP VS Code extension and I am able to configure it for one endpoint. What if I want to upload a file to multiple servers? How can I configure that? Or is there another extension that does that?
Hi you can add multiple ftp servers to config. Just The context must not be same.
[
{
"name": "server1",
"context": "/project/build",
"host": "host",
"username": "username",
"password": "password",
"remotePath": "/remote/project/build"
},
{
"name": "server2",
"context": "/project/src",
"host": "host",
"username": "username",
"password": "password",
"remotePath": "/remote/project/src"
}
]
You can use "profiles" with the SFTP extension now. https://github.com/liximomo/vscode-sftp#profiles
{
"name": "My Project",
"protocol": "sftp",
"remotePath": "/",
"port": 22,
"profiles": {
"dev": {
"host": "server1.example.com",
"username": "username",
"password": "password"
},
"prod": {
"host": "server2.example.com",
"username": "other-username",
"password": "other-password"
}
},
"defaultProfile": "dev"
}
You can set up remotePath for each of your profiles like that: (I saw that such question was asked by #Charlie Parker in the second answer to that question)
{
"name": "ExampleName",
"protocol": "sftp",
"port": 22,
"profiles": {
"profile1": {
"host": "connection1",
"username": "user1",
"remotePath":"/path1"
},
"profile2": {
"host": "connection2",
"username": "user2",
"remotePath":"/path2"
},
"profile3": {
"host": "connection3",
"username": "user3",
"remotePath":"/path3"
},
}
}
And with Ctrl+Sifht+P > Set Profile you can change your profile.
There are lot of add-ins that will work for your requirements. Below are a list of few
https://marketplace.visualstudio.com/items?itemName=mkloubert.vs-deploy
https://marketplace.visualstudio.com/items?itemName=mkloubert.vscode-deploy-reloaded
https://marketplace.visualstudio.com/items?itemName=humy2833.ftp-simple
Try this:
[
{
"name": "project 1",
"context": "/project/project1",
"host": "",
"username": "",
"password": "",
"protocol": "ftp",
"post": 21,
"remotePath": "/",
"uploadOnSave": true
},
{
"name": "project 2",
"context": "/project/project2",
"host": "",
"username": "",
"password": "",
"protocol": "ftp",
"post": 21,
"remotePath": "/",
"uploadOnSave": true
}
]
[
{
"name": "server1",
"context": "/project/build",
"host": "host",
"username": "username",
"password": "password",
"remotePath": "/remote/project/build"
},
{
"name": "server2",
"context": "/project/src",
"host": "host",
"username": "username",
"password": "password",
"remotePath": "/remote/project/src"
}
]