How To Configure Email Template Auth0
Our default email flow can address the requirements of most applications. Sometimes, however, you may require more flexibility, such every bit when implementing:
-
localization
-
custom Redirect To URLs based on user or tenant
-
different electronic mail templates per application or tenant
The Auth0 Management API provides endpoints to help yous manage your email flow to control when and how emails are sent. If necessary, you can also implement your ain Custom Email endpoints and utilize the Auth0 Management API endpoints to assistance manage the rest of the flow.
Verification emails
A verification email should be sent to every user for which the email_verified property is false. Typically, these are users in database connections or users authenticating with social providers that practice not validate email addresses upon new user registration.
Y'all tin send verification emails in more than one way:
The Send an email address verification email endpoint sends the user an email prompting them to verify their email address.
gyre --request Postal service \ --url 'https://YOUR_DOMAIN/api/v2/jobs/verification-email' \ --header 'authorization: Bearer MGMT_API_ACCESS_TOKEN' \ --header 'content-type: awarding/json' \ --data '{ "user_id": "USER_ID_TO_SEND_VERIFY_EMAIL_TO", "client_id": "YOUR_APPLICATION_CLIENT_ID","identity": {"user_id": "5457edea1b8f22891a000004","provider": "google-oauth2"}, "organization_id": "YOUR_ORGANIZATION_ID" }' var client = new RestClient("https://YOUR_DOMAIN/api/v2/jobs/verification-email"); var asking = new RestRequest(Method.Post); request.AddHeader("content-type", "application/json"); request.AddHeader("authorization", "Bearer MGMT_API_ACCESS_TOKEN"); asking.AddParameter("awarding/json", "{ \"user_id\": \"USER_ID_TO_SEND_VERIFY_EMAIL_TO\", \"client_id\": \"YOUR_APPLICATION_CLIENT_ID\",\"identity\": {\"user_id\": \"5457edea1b8f22891a000004\",\"provider\": \"google-oauth2\"}, \"organization_id\": \"YOUR_ORGANIZATION_ID\" }", ParameterType.RequestBody); IRestResponse response = client.Execute(request); packet main import ( "fmt" "strings" "cyberspace/http" "io/ioutil" ) func main() { url := "https://YOUR_DOMAIN/api/v2/jobs/verification-email" payload := strings.NewReader("{ \"user_id\": \"USER_ID_TO_SEND_VERIFY_EMAIL_TO\", \"client_id\": \"YOUR_APPLICATION_CLIENT_ID\",\"identity\": {\"user_id\": \"5457edea1b8f22891a000004\",\"provider\": \"google-oauth2\"}, \"organization_id\": \"YOUR_ORGANIZATION_ID\" }") req, _ := http.NewRequest("Post", url, payload) req.Header.Add("content-blazon", "application/json") req.Header.Add("authorization", "Bearer MGMT_API_ACCESS_TOKEN") res, _ := http.DefaultClient.Do(req) defer res.Torso.Close() torso, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(cord(body)) } HttpResponse<String> response = Unirest.post("https://YOUR_DOMAIN/api/v2/jobs/verification-email") .header("content-type", "application/json") .header("authorization", "Bearer MGMT_API_ACCESS_TOKEN") .body("{ \"user_id\": \"USER_ID_TO_SEND_VERIFY_EMAIL_TO\", \"client_id\": \"YOUR_APPLICATION_CLIENT_ID\",\"identity\": {\"user_id\": \"5457edea1b8f22891a000004\",\"provider\": \"google-oauth2\"}, \"organization_id\": \"YOUR_ORGANIZATION_ID\" }") .asString(); var axios = require("axios").default; var options = { method: 'Post', url: 'https://YOUR_DOMAIN/api/v2/jobs/verification-e-mail', headers: { 'content-blazon': 'awarding/json', authorization: 'Bearer MGMT_API_ACCESS_TOKEN' }, data: { user_id: 'USER_ID_TO_SEND_VERIFY_EMAIL_TO', client_id: 'YOUR_APPLICATION_CLIENT_ID', identity: {user_id: '5457edea1b8f22891a000004', provider: 'google-oauth2'}, organization_id: 'YOUR_ORGANIZATION_ID' } }; axios.asking(options).and so(part (response) { console.log(response.data); }).catch(part (error) { console.error(error); }); #import <Foundation/Foundation.h> NSDictionary *headers = @{ @"content-type": @"awarding/json", @"potency": @"Bearer MGMT_API_ACCESS_TOKEN" }; NSDictionary *parameters = @{ @"user_id": @"USER_ID_TO_SEND_VERIFY_EMAIL_TO", @"client_id": @"YOUR_APPLICATION_CLIENT_ID", @"identity": @{ @"user_id": @"5457edea1b8f22891a000004", @"provider": @"google-oauth2" }, @"organization_id": @"YOUR_ORGANIZATION_ID" }; NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 mistake:nil]; NSMutableURLRequest *asking = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://YOUR_DOMAIN/api/v2/jobs/verification-email"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; [request setHTTPMethod:@"POST"]; [request setAllHTTPHeaderFields:headers]; [request setHTTPBody:postData]; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:asking completionHandler:^(NSData *data, NSURLResponse *response, NSError *fault) { if (error) { NSLog(@"%@", mistake); } else { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSLog(@"%@", httpResponse); } }]; [dataTask resume]; $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://YOUR_DOMAIN/api/v2/jobs/verification-electronic mail", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{ \"user_id\": \"USER_ID_TO_SEND_VERIFY_EMAIL_TO\", \"client_id\": \"YOUR_APPLICATION_CLIENT_ID\",\"identity\": {\"user_id\": \"5457edea1b8f22891a000004\",\"provider\": \"google-oauth2\"}, \"organization_id\": \"YOUR_ORGANIZATION_ID\" }", CURLOPT_HTTPHEADER => [ "authorization: Bearer MGMT_API_ACCESS_TOKEN", "content-type: awarding/json" ], ]); $response = curl_exec($scroll); $err = curl_error($gyre); curl_close($roll); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } import http.customer conn = http.client.HTTPSConnection("") payload = "{ \"user_id\": \"USER_ID_TO_SEND_VERIFY_EMAIL_TO\", \"client_id\": \"YOUR_APPLICATION_CLIENT_ID\",\"identity\": {\"user_id\": \"5457edea1b8f22891a000004\",\"provider\": \"google-oauth2\"}, \"organization_id\": \"YOUR_ORGANIZATION_ID\" }" headers = { 'content-type': "application/json", 'authorization': "Bearer MGMT_API_ACCESS_TOKEN" } conn.request("POST", "/YOUR_DOMAIN/api/v2/jobs/verification-electronic mail", payload, headers) res = conn.getresponse() information = res.read() impress(data.decode("utf-eight")) require 'uri' require 'cyberspace/http' crave 'openssl' url = URI("https://YOUR_DOMAIN/api/v2/jobs/verification-email") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(url) asking["content-type"] = 'application/json' request["authorization"] = 'Bearer MGMT_API_ACCESS_TOKEN' request.torso = "{ \"user_id\": \"USER_ID_TO_SEND_VERIFY_EMAIL_TO\", \"client_id\": \"YOUR_APPLICATION_CLIENT_ID\",\"identity\": {\"user_id\": \"5457edea1b8f22891a000004\",\"provider\": \"google-oauth2\"}, \"organization_id\": \"YOUR_ORGANIZATION_ID\" }" response = http.request(request) puts response.read_body import Foundation let headers = [ "content-blazon": "application/json", "authority": "Bearer MGMT_API_ACCESS_TOKEN" ] let parameters = [ "user_id": "USER_ID_TO_SEND_VERIFY_EMAIL_TO", "client_id": "YOUR_APPLICATION_CLIENT_ID", "identity": [ "user_id": "5457edea1b8f22891a000004", "provider": "google-oauth2" ], "organization_id": "YOUR_ORGANIZATION_ID" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://YOUR_DOMAIN/api/v2/jobs/verification-email")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "Postal service" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, fault) -> Void in if (error != nil) { impress(mistake) } else { let httpResponse = response every bit? HTTPURLResponse print(httpResponse) } }) dataTask.resume()
Require verified email for login
You tin can require users to verify their electronic mail earlier logging in with a rule:
part (user, context, callback) { if (!user.email_verified) { render callback(new UnauthorizedError('Delight verify your email before logging in.')); } else { return callback(nil, user, context); } }
Custom redirects
A custom redirect is useful when you desire to direct users to sure URLs based on user attributes or on the tenant. The Auth0 Direction API provides a Create Email Verification Ticket endpoint that generates the verification link for each user. This endpoint allows you to specify the result_url to which users volition be redirected afterward they have validated their e-mail address by clicking the link in the verification email.
We recommend AllowList the URL in the Auth0 Dashboard. For details, run across Add Addresses to AllowList.
Welcome emails
A welcome email is sent to users in one case they take verified their electronic mail address.
Send welcome email using your ain API
Using a rule, you tin can call your API to send a welcome email only if the user'southward electronic mail address has been verified and the e-mail has not been sent previously.
part (user, context, callback) { const request = require('asking'); if (!user.email_verified || user.welcome_email_sent) { return callback(zippo, user, context); } asking.mail service({ url: 'https://yourapi.yourcompany.com/postal service/welcome', json: { user: user, context: context, secretToken: configuration.MY_SECRET_TOKEN, }, timeout: 5000 }, function(err, response, body){ if (err) return callback(new Error(err)); // Email sent flag persisted in the user's profile. user.app_metadata.welcome_email_sent = true; return callback(nada, user, context); }); }
Modify password confirmation emails
To handle password change requests, you volition need to host a course to capture the user's new password, and post it to the Create Countersign Alter Ticket endpoint in the new_password parameter. Calling this endpoint will generate a Change Password Confirmation link. With it, you can send the user an email containing the link. When the user clicks the link, they can update their countersign.
Alternatively, if y'all invoke the endpoint without specifying the new_password parameter, the link in the electronic mail will redirect the user to a page prompting them to set a new password.
Acquire more
- Customize E-mail Templates
- Configure External SMTP E-mail Providers
How To Configure Email Template Auth0,
Source: https://auth0.com/docs/customize/email/manage-email-flow
Posted by: torresthereenewhe.blogspot.com

0 Response to "How To Configure Email Template Auth0"
Post a Comment