Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion main/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"seo": {
"metatags": {
"canonical": "https://auth0.com/docs"
"canonical": "https://auth0.com"
}
},
"banner": {
Expand Down
176 changes: 98 additions & 78 deletions main/docs/authenticate/database-connections/password-change.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ title: Change Users' Passwords
---
import {AuthCodeBlock} from "/snippets/AuthCodeBlock.jsx";

import {AuthCodeGroup} from "/snippets/AuthCodeGroup.jsx";

<Card title="Overview">

Key Concepts
Expand Down Expand Up @@ -59,16 +61,22 @@ Go to [Auth0 Dashboard > Applications > Applications](https://manage.auth0.com/#

If your connection is a custom database, check to see if the user exists in the database before you invoke the Authentication API for `changePassword`.

export const codeExample1 = `curl --request POST \
<AuthCodeGroup>
```bash cURL
curl --request POST \
--url 'https://{yourDomain}/dbconnections/change_password' \
--header 'content-type: application/json' \
--data '{"client_id": "{yourClientId}","email": "","connection": "Username-Password-Authentication"}'`;
export const codeExample2 = `var client = new RestClient("https://{yourDomain}/dbconnections/change_password");
--data '{"client_id": "{yourClientId}","email": "","connection": "Username-Password-Authentication"}'
```
```csharp C#
var client = new RestClient("https://{yourDomain}/dbconnections/change_password");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);`;
export const codeExample3 = `package main
request.AddParameter("application/json", "{"client_id": "{yourClientId}","email": "","connection": "Username-Password-Authentication"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```
```go Go
package main

import (
"fmt"
Expand All @@ -81,7 +89,7 @@ func main() {

url := "https://{yourDomain}/dbconnections/change_password"

payload := strings.NewReader("{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}")
payload := strings.NewReader("{"client_id": "{yourClientId}","email": "","connection": "Username-Password-Authentication"}")

req, _ := http.NewRequest("POST", url, payload)

Expand All @@ -95,12 +103,16 @@ func main() {
fmt.Println(res)
fmt.Println(string(body))

}`;
export const codeExample4 = `HttpResponse<String> response = Unirest.post("https://{yourDomain}/dbconnections/change_password")
}
```
```java Java
HttpResponse<String> response = Unirest.post("https://{yourDomain}/dbconnections/change_password")
.header("content-type", "application/json")
.body("{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}")
.asString();`;
export const codeExample5 = `var axios = require("axios").default;
.body("{"client_id": "{yourClientId}","email": "","connection": "Username-Password-Authentication"}")
.asString();
```
```javascript Node.JS
var axios = require("axios").default;

var options = {
method: 'POST',
Expand All @@ -117,8 +129,10 @@ axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});`;
export const codeExample6 = `#import <Foundation/Foundation.h>
});
```
```obj-c Obj-C
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/json" };
NSDictionary *parameters = @{ @"client_id": @"{yourClientId}",
Expand All @@ -144,8 +158,10 @@ NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];`;
export const codeExample7 = `$curl = curl_init();
[dataTask resume];
```
```php PHP
$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://{yourDomain}/dbconnections/change_password",
Expand All @@ -155,7 +171,7 @@ curl_setopt_array($curl, [
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}",
CURLOPT_POSTFIELDS => "{"client_id": "{yourClientId}","email": "","connection": "Username-Password-Authentication"}",
CURLOPT_HTTPHEADER => [
"content-type: application/json"
],
Expand All @@ -170,12 +186,14 @@ if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}`;
export const codeExample8 = `import http.client
}
```
```python Python
import http.client

conn = http.client.HTTPSConnection("")

payload = "{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}"
payload = "{"client_id": "{yourClientId}","email": "","connection": "Username-Password-Authentication"}"

headers = { 'content-type': "application/json" }

Expand All @@ -184,8 +202,10 @@ conn.request("POST", "/{yourDomain}/dbconnections/change_password", payload, hea
res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))`;
export const codeExample9 = `require 'uri'
print(data.decode("utf-8"))
```
```ruby Ruby
require 'uri'
require 'net/http'
require 'openssl'

Expand All @@ -197,11 +217,13 @@ http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request.body = "{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}"
request.body = "{"client_id": "{yourClientId}","email": "","connection": "Username-Password-Authentication"}"

response = http.request(request)
puts response.read_body`;
export const codeExample10 = `import Foundation
puts response.read_body
```
```swift Swift
import Foundation

let headers = ["content-type": "application/json"]
let parameters = [
Expand Down Expand Up @@ -229,20 +251,9 @@ let dataTask = session.dataTask(with: request as URLRequest, completionHandler:
}
})

dataTask.resume()`;

<CodeGroup>
<AuthCodeBlock children={codeExample1} language="bash" filename="cURL" />
<AuthCodeBlock children={codeExample2} language="csharp" filename="C#" />
<AuthCodeBlock children={codeExample3} language="go" filename="Go" />
<AuthCodeBlock children={codeExample4} language="java" filename="Java" />
<AuthCodeBlock children={codeExample5} language="javascript" filename="Node.JS" />
<AuthCodeBlock children={codeExample6} language="obj-c" filename="Obj-C" />
<AuthCodeBlock children={codeExample7} language="php" filename="PHP" />
<AuthCodeBlock children={codeExample8} language="python" filename="Python" />
<AuthCodeBlock children={codeExample9} language="ruby" filename="Ruby" />
<AuthCodeBlock children={codeExample10} language="swift" filename="Swift" />
</CodeGroup>
dataTask.resume()
```
</AuthCodeGroup>

### Password reset email

Expand Down Expand Up @@ -291,18 +302,24 @@ If you use Management API to set or update a user's password via the [Update a U

</Callout>

export const codeExample11 = `curl --request PATCH \
<AuthCodeGroup>
```bash cURL
curl --request PATCH \
--url 'https://{yourDomain}/api/v2/users/%7BuserId%7D' \
--header 'authorization: Bearer {yourMgmtApiAccessToken}' \
--header 'content-type: application/json' \
--data '{"password": "newPassword","connection": "connectionName"}'`;
export const codeExample12 = `var client = new RestClient("https://{yourDomain}/api/v2/users/%7BuserId%7D");
--data '{"password": "newPassword","connection": "connectionName"}'
```
```csharp C#
var client = new RestClient("https://{yourDomain}/api/v2/users/%7BuserId%7D");
var request = new RestRequest(Method.PATCH);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer {yourMgmtApiAccessToken}");
request.AddParameter("application/json", "{\"password\": \"newPassword\",\"connection\": \"connectionName\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);`;
export const codeExample13 = `package main
request.AddParameter("application/json", "{"password": "newPassword","connection": "connectionName"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```
```go Go
package main

import (
"fmt"
Expand All @@ -315,7 +332,7 @@ func main() {

url := "https://{yourDomain}/api/v2/users/%7BuserId%7D"

payload := strings.NewReader("{\"password\": \"newPassword\",\"connection\": \"connectionName\"}")
payload := strings.NewReader("{"password": "newPassword","connection": "connectionName"}")

req, _ := http.NewRequest("PATCH", url, payload)

Expand All @@ -330,13 +347,17 @@ func main() {
fmt.Println(res)
fmt.Println(string(body))

}`;
export const codeExample14 = `HttpResponse<String> response = Unirest.patch("https://{yourDomain}/api/v2/users/%7BuserId%7D")
}
```
```java Java
HttpResponse<String> response = Unirest.patch("https://{yourDomain}/api/v2/users/%7BuserId%7D")
.header("content-type", "application/json")
.header("authorization", "Bearer {yourMgmtApiAccessToken}")
.body("{\"password\": \"newPassword\",\"connection\": \"connectionName\"}")
.asString();`;
export const codeExample15 = `var axios = require("axios").default;
.body("{"password": "newPassword","connection": "connectionName"}")
.asString();
```
```javascript Node.JS
var axios = require("axios").default;

var options = {
method: 'PATCH',
Expand All @@ -352,8 +373,10 @@ axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});`;
export const codeExample16 = `#import <Foundation/Foundation.h>
});
```
```obj-c Obj-C
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/json",
@"authorization": @"Bearer {yourMgmtApiAccessToken}" };
Expand All @@ -379,8 +402,10 @@ NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];`;
export const codeExample17 = `$curl = curl_init();
[dataTask resume];
```
```php PHP
$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://{yourDomain}/api/v2/users/%7BuserId%7D",
Expand All @@ -390,7 +415,7 @@ curl_setopt_array($curl, [
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => "{\"password\": \"newPassword\",\"connection\": \"connectionName\"}",
CURLOPT_POSTFIELDS => "{"password": "newPassword","connection": "connectionName"}",
CURLOPT_HTTPHEADER => [
"authorization: Bearer {yourMgmtApiAccessToken}",
"content-type: application/json"
Expand All @@ -406,12 +431,14 @@ if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}`;
export const codeExample18 = `import http.client
}
```
```python Python
import http.client

conn = http.client.HTTPSConnection("")

payload = "{\"password\": \"newPassword\",\"connection\": \"connectionName\"}"
payload = "{"password": "newPassword","connection": "connectionName"}"

headers = {
'content-type': "application/json",
Expand All @@ -423,8 +450,10 @@ conn.request("PATCH", "/{yourDomain}/api/v2/users/%7BuserId%7D", payload, header
res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))`;
export const codeExample19 = `require 'uri'
print(data.decode("utf-8"))
```
```ruby Ruby
require 'uri'
require 'net/http'
require 'openssl'

Expand All @@ -437,11 +466,13 @@ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Patch.new(url)
request["content-type"] = 'application/json'
request["authorization"] = 'Bearer {yourMgmtApiAccessToken}'
request.body = "{\"password\": \"newPassword\",\"connection\": \"connectionName\"}"
request.body = "{"password": "newPassword","connection": "connectionName"}"

response = http.request(request)
puts response.read_body`;
export const codeExample20 = `import Foundation
puts response.read_body
```
```swift Swift
import Foundation

let headers = [
"content-type": "application/json",
Expand Down Expand Up @@ -471,20 +502,9 @@ let dataTask = session.dataTask(with: request as URLRequest, completionHandler:
}
})

dataTask.resume()`;

<CodeGroup>
<AuthCodeBlock children={codeExample11} language="bash" filename="cURL" />
<AuthCodeBlock children={codeExample12} language="csharp" filename="C#" />
<AuthCodeBlock children={codeExample13} language="go" filename="Go" />
<AuthCodeBlock children={codeExample14} language="java" filename="Java" />
<AuthCodeBlock children={codeExample15} language="javascript" filename="Node.JS" />
<AuthCodeBlock children={codeExample16} language="obj-c" filename="Obj-C" />
<AuthCodeBlock children={codeExample17} language="php" filename="PHP" />
<AuthCodeBlock children={codeExample18} language="python" filename="Python" />
<AuthCodeBlock children={codeExample19} language="ruby" filename="Ruby" />
<AuthCodeBlock children={codeExample20} language="swift" filename="Swift" />
</CodeGroup>
dataTask.resume()
```
</AuthCodeGroup>

### Manually set users' passwords using the Auth0 Dashboard

Expand Down
Loading