Auth0 implmentation with .net core 2.1












0















Unable to create token in auth0 using C#



var client = new RestClient("https://domain/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");request.AddParameter("application/json", "{"client_id":"#####","cli``ent_secret":"####","audience":"https://domain/api/v2/users","grant_type":"client_credentials"}", ParameterType.RequestBody);IRestResponse response = client.Execute(request);



Giving :
{
"error": "access_denied",
"error_description": "Service not enabled within domain: https://satyamdev.auth0.com/api/v2/users/"
}










share|improve this question























  • Have you ever configure "Cors"?, I Think this is the problem

    – Simon Restrepo
    Nov 27 '18 at 14:05
















0















Unable to create token in auth0 using C#



var client = new RestClient("https://domain/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");request.AddParameter("application/json", "{"client_id":"#####","cli``ent_secret":"####","audience":"https://domain/api/v2/users","grant_type":"client_credentials"}", ParameterType.RequestBody);IRestResponse response = client.Execute(request);



Giving :
{
"error": "access_denied",
"error_description": "Service not enabled within domain: https://satyamdev.auth0.com/api/v2/users/"
}










share|improve this question























  • Have you ever configure "Cors"?, I Think this is the problem

    – Simon Restrepo
    Nov 27 '18 at 14:05














0












0








0








Unable to create token in auth0 using C#



var client = new RestClient("https://domain/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");request.AddParameter("application/json", "{"client_id":"#####","cli``ent_secret":"####","audience":"https://domain/api/v2/users","grant_type":"client_credentials"}", ParameterType.RequestBody);IRestResponse response = client.Execute(request);



Giving :
{
"error": "access_denied",
"error_description": "Service not enabled within domain: https://satyamdev.auth0.com/api/v2/users/"
}










share|improve this question














Unable to create token in auth0 using C#



var client = new RestClient("https://domain/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");request.AddParameter("application/json", "{"client_id":"#####","cli``ent_secret":"####","audience":"https://domain/api/v2/users","grant_type":"client_credentials"}", ParameterType.RequestBody);IRestResponse response = client.Execute(request);



Giving :
{
"error": "access_denied",
"error_description": "Service not enabled within domain: https://satyamdev.auth0.com/api/v2/users/"
}







auth0






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 13:20









Satyam SinghSatyam Singh

83




83













  • Have you ever configure "Cors"?, I Think this is the problem

    – Simon Restrepo
    Nov 27 '18 at 14:05



















  • Have you ever configure "Cors"?, I Think this is the problem

    – Simon Restrepo
    Nov 27 '18 at 14:05

















Have you ever configure "Cors"?, I Think this is the problem

– Simon Restrepo
Nov 27 '18 at 14:05





Have you ever configure "Cors"?, I Think this is the problem

– Simon Restrepo
Nov 27 '18 at 14:05












1 Answer
1






active

oldest

votes


















1














I think you are providing undefined API identifier (audience) in the request. The audience parameter should be https://[domain].auth0.com/api/v2/.



Example curl command:



Executing client credential Grant type to get the token.



curl --request POST 
--url 'https://[Domain].auth0.com/oauth/token'
--header 'content-type: application/json'
--data '{"grant_type":"client_credentials","client_id":"[Client ID]","client_secret": "[Client secret]","audience": "https://[Domain].auth0.com/api/v2/"}'


After getting the token you can make an HTTP get request to endpoint /api/v2/users/{id} to get the whole user profile.



Curl Command:



curl -X GET 
--url "https://[Domain].auth0.com/api/v2/users"
-H "Content-Type:application/json"
-H "Authorization:Bearer [Token]"


In Dotnet core 2.1, you can try the following to get the token and use the token to get the users:



using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ClientCredentials {
class Program {
private static string accessToken;
private static async Task Main (string args) {
await ClientCredentialsFlow ();
await GetUsers ();
// await CreateUser();
}

protected static async Task ClientCredentialsFlow () {

var body = new Model {
grant_type = "client_credentials",
client_id = "[client id]",
client_secret = "[client secret]",
audience = "https://[domain].auth0.com/api/v2/"
};

using (var client = new HttpClient ()) {
var content = JsonConvert.SerializeObject (body);
var stringContent = new StringContent (content, Encoding.UTF8, "application/json");
var res = await client.PostAsync ("https://[domain].auth0.com/oauth/token", stringContent);
var responseBody = await res.Content.ReadAsStringAsync ();
var deserilizeBody = JsonConvert.DeserializeObject<AuthResponseModel> (responseBody);
accessToken = deserilizeBody.access_token;
Console.WriteLine (accessToken);

}

}
protected static async Task GetUsers () {
using (var client = new HttpClient ()) {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue ("Bearer", accessToken);
var response = await client.GetAsync ("https://[domain].auth0.com/api/v2/users");
var responseBody = await response.Content.ReadAsStringAsync ();
Console.WriteLine ("==============================");
Console.WriteLine (responseBody);

}
}

internal class Model {

public string grant_type { get; set; }
public string client_id { get; set; }
public string client_secret { get; set; }
public string audience { get; set; }
}

internal class AuthResponseModel {
public string access_token { get; set; }
public string scopes { get; set; }
public string expires_in { get; set; }
public string token_type { get; set; }
}

internal class User {
public string email { get; set; }
public bool email_verified { get; set; }
public string connection { get; set; }
public string username { get; set; }
public string password { get; set; }

}

}
}


Note: To call /api/v2/users endpoint, you need to have correct permissions (read:users).






share|improve this answer
























  • we use " https://[domain].auth0.com/api/v2/" when , we want to create token , but I have to create user into Aouth0 DB , so that we have to call " https://[domain].auth0.com/api/v2/users" which is reserved API.

    – Satyam Singh
    Nov 28 '18 at 12:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53500673%2fauth0-implmentation-with-net-core-2-1%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I think you are providing undefined API identifier (audience) in the request. The audience parameter should be https://[domain].auth0.com/api/v2/.



Example curl command:



Executing client credential Grant type to get the token.



curl --request POST 
--url 'https://[Domain].auth0.com/oauth/token'
--header 'content-type: application/json'
--data '{"grant_type":"client_credentials","client_id":"[Client ID]","client_secret": "[Client secret]","audience": "https://[Domain].auth0.com/api/v2/"}'


After getting the token you can make an HTTP get request to endpoint /api/v2/users/{id} to get the whole user profile.



Curl Command:



curl -X GET 
--url "https://[Domain].auth0.com/api/v2/users"
-H "Content-Type:application/json"
-H "Authorization:Bearer [Token]"


In Dotnet core 2.1, you can try the following to get the token and use the token to get the users:



using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ClientCredentials {
class Program {
private static string accessToken;
private static async Task Main (string args) {
await ClientCredentialsFlow ();
await GetUsers ();
// await CreateUser();
}

protected static async Task ClientCredentialsFlow () {

var body = new Model {
grant_type = "client_credentials",
client_id = "[client id]",
client_secret = "[client secret]",
audience = "https://[domain].auth0.com/api/v2/"
};

using (var client = new HttpClient ()) {
var content = JsonConvert.SerializeObject (body);
var stringContent = new StringContent (content, Encoding.UTF8, "application/json");
var res = await client.PostAsync ("https://[domain].auth0.com/oauth/token", stringContent);
var responseBody = await res.Content.ReadAsStringAsync ();
var deserilizeBody = JsonConvert.DeserializeObject<AuthResponseModel> (responseBody);
accessToken = deserilizeBody.access_token;
Console.WriteLine (accessToken);

}

}
protected static async Task GetUsers () {
using (var client = new HttpClient ()) {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue ("Bearer", accessToken);
var response = await client.GetAsync ("https://[domain].auth0.com/api/v2/users");
var responseBody = await response.Content.ReadAsStringAsync ();
Console.WriteLine ("==============================");
Console.WriteLine (responseBody);

}
}

internal class Model {

public string grant_type { get; set; }
public string client_id { get; set; }
public string client_secret { get; set; }
public string audience { get; set; }
}

internal class AuthResponseModel {
public string access_token { get; set; }
public string scopes { get; set; }
public string expires_in { get; set; }
public string token_type { get; set; }
}

internal class User {
public string email { get; set; }
public bool email_verified { get; set; }
public string connection { get; set; }
public string username { get; set; }
public string password { get; set; }

}

}
}


Note: To call /api/v2/users endpoint, you need to have correct permissions (read:users).






share|improve this answer
























  • we use " https://[domain].auth0.com/api/v2/" when , we want to create token , but I have to create user into Aouth0 DB , so that we have to call " https://[domain].auth0.com/api/v2/users" which is reserved API.

    – Satyam Singh
    Nov 28 '18 at 12:09
















1














I think you are providing undefined API identifier (audience) in the request. The audience parameter should be https://[domain].auth0.com/api/v2/.



Example curl command:



Executing client credential Grant type to get the token.



curl --request POST 
--url 'https://[Domain].auth0.com/oauth/token'
--header 'content-type: application/json'
--data '{"grant_type":"client_credentials","client_id":"[Client ID]","client_secret": "[Client secret]","audience": "https://[Domain].auth0.com/api/v2/"}'


After getting the token you can make an HTTP get request to endpoint /api/v2/users/{id} to get the whole user profile.



Curl Command:



curl -X GET 
--url "https://[Domain].auth0.com/api/v2/users"
-H "Content-Type:application/json"
-H "Authorization:Bearer [Token]"


In Dotnet core 2.1, you can try the following to get the token and use the token to get the users:



using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ClientCredentials {
class Program {
private static string accessToken;
private static async Task Main (string args) {
await ClientCredentialsFlow ();
await GetUsers ();
// await CreateUser();
}

protected static async Task ClientCredentialsFlow () {

var body = new Model {
grant_type = "client_credentials",
client_id = "[client id]",
client_secret = "[client secret]",
audience = "https://[domain].auth0.com/api/v2/"
};

using (var client = new HttpClient ()) {
var content = JsonConvert.SerializeObject (body);
var stringContent = new StringContent (content, Encoding.UTF8, "application/json");
var res = await client.PostAsync ("https://[domain].auth0.com/oauth/token", stringContent);
var responseBody = await res.Content.ReadAsStringAsync ();
var deserilizeBody = JsonConvert.DeserializeObject<AuthResponseModel> (responseBody);
accessToken = deserilizeBody.access_token;
Console.WriteLine (accessToken);

}

}
protected static async Task GetUsers () {
using (var client = new HttpClient ()) {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue ("Bearer", accessToken);
var response = await client.GetAsync ("https://[domain].auth0.com/api/v2/users");
var responseBody = await response.Content.ReadAsStringAsync ();
Console.WriteLine ("==============================");
Console.WriteLine (responseBody);

}
}

internal class Model {

public string grant_type { get; set; }
public string client_id { get; set; }
public string client_secret { get; set; }
public string audience { get; set; }
}

internal class AuthResponseModel {
public string access_token { get; set; }
public string scopes { get; set; }
public string expires_in { get; set; }
public string token_type { get; set; }
}

internal class User {
public string email { get; set; }
public bool email_verified { get; set; }
public string connection { get; set; }
public string username { get; set; }
public string password { get; set; }

}

}
}


Note: To call /api/v2/users endpoint, you need to have correct permissions (read:users).






share|improve this answer
























  • we use " https://[domain].auth0.com/api/v2/" when , we want to create token , but I have to create user into Aouth0 DB , so that we have to call " https://[domain].auth0.com/api/v2/users" which is reserved API.

    – Satyam Singh
    Nov 28 '18 at 12:09














1












1








1







I think you are providing undefined API identifier (audience) in the request. The audience parameter should be https://[domain].auth0.com/api/v2/.



Example curl command:



Executing client credential Grant type to get the token.



curl --request POST 
--url 'https://[Domain].auth0.com/oauth/token'
--header 'content-type: application/json'
--data '{"grant_type":"client_credentials","client_id":"[Client ID]","client_secret": "[Client secret]","audience": "https://[Domain].auth0.com/api/v2/"}'


After getting the token you can make an HTTP get request to endpoint /api/v2/users/{id} to get the whole user profile.



Curl Command:



curl -X GET 
--url "https://[Domain].auth0.com/api/v2/users"
-H "Content-Type:application/json"
-H "Authorization:Bearer [Token]"


In Dotnet core 2.1, you can try the following to get the token and use the token to get the users:



using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ClientCredentials {
class Program {
private static string accessToken;
private static async Task Main (string args) {
await ClientCredentialsFlow ();
await GetUsers ();
// await CreateUser();
}

protected static async Task ClientCredentialsFlow () {

var body = new Model {
grant_type = "client_credentials",
client_id = "[client id]",
client_secret = "[client secret]",
audience = "https://[domain].auth0.com/api/v2/"
};

using (var client = new HttpClient ()) {
var content = JsonConvert.SerializeObject (body);
var stringContent = new StringContent (content, Encoding.UTF8, "application/json");
var res = await client.PostAsync ("https://[domain].auth0.com/oauth/token", stringContent);
var responseBody = await res.Content.ReadAsStringAsync ();
var deserilizeBody = JsonConvert.DeserializeObject<AuthResponseModel> (responseBody);
accessToken = deserilizeBody.access_token;
Console.WriteLine (accessToken);

}

}
protected static async Task GetUsers () {
using (var client = new HttpClient ()) {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue ("Bearer", accessToken);
var response = await client.GetAsync ("https://[domain].auth0.com/api/v2/users");
var responseBody = await response.Content.ReadAsStringAsync ();
Console.WriteLine ("==============================");
Console.WriteLine (responseBody);

}
}

internal class Model {

public string grant_type { get; set; }
public string client_id { get; set; }
public string client_secret { get; set; }
public string audience { get; set; }
}

internal class AuthResponseModel {
public string access_token { get; set; }
public string scopes { get; set; }
public string expires_in { get; set; }
public string token_type { get; set; }
}

internal class User {
public string email { get; set; }
public bool email_verified { get; set; }
public string connection { get; set; }
public string username { get; set; }
public string password { get; set; }

}

}
}


Note: To call /api/v2/users endpoint, you need to have correct permissions (read:users).






share|improve this answer













I think you are providing undefined API identifier (audience) in the request. The audience parameter should be https://[domain].auth0.com/api/v2/.



Example curl command:



Executing client credential Grant type to get the token.



curl --request POST 
--url 'https://[Domain].auth0.com/oauth/token'
--header 'content-type: application/json'
--data '{"grant_type":"client_credentials","client_id":"[Client ID]","client_secret": "[Client secret]","audience": "https://[Domain].auth0.com/api/v2/"}'


After getting the token you can make an HTTP get request to endpoint /api/v2/users/{id} to get the whole user profile.



Curl Command:



curl -X GET 
--url "https://[Domain].auth0.com/api/v2/users"
-H "Content-Type:application/json"
-H "Authorization:Bearer [Token]"


In Dotnet core 2.1, you can try the following to get the token and use the token to get the users:



using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ClientCredentials {
class Program {
private static string accessToken;
private static async Task Main (string args) {
await ClientCredentialsFlow ();
await GetUsers ();
// await CreateUser();
}

protected static async Task ClientCredentialsFlow () {

var body = new Model {
grant_type = "client_credentials",
client_id = "[client id]",
client_secret = "[client secret]",
audience = "https://[domain].auth0.com/api/v2/"
};

using (var client = new HttpClient ()) {
var content = JsonConvert.SerializeObject (body);
var stringContent = new StringContent (content, Encoding.UTF8, "application/json");
var res = await client.PostAsync ("https://[domain].auth0.com/oauth/token", stringContent);
var responseBody = await res.Content.ReadAsStringAsync ();
var deserilizeBody = JsonConvert.DeserializeObject<AuthResponseModel> (responseBody);
accessToken = deserilizeBody.access_token;
Console.WriteLine (accessToken);

}

}
protected static async Task GetUsers () {
using (var client = new HttpClient ()) {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue ("Bearer", accessToken);
var response = await client.GetAsync ("https://[domain].auth0.com/api/v2/users");
var responseBody = await response.Content.ReadAsStringAsync ();
Console.WriteLine ("==============================");
Console.WriteLine (responseBody);

}
}

internal class Model {

public string grant_type { get; set; }
public string client_id { get; set; }
public string client_secret { get; set; }
public string audience { get; set; }
}

internal class AuthResponseModel {
public string access_token { get; set; }
public string scopes { get; set; }
public string expires_in { get; set; }
public string token_type { get; set; }
}

internal class User {
public string email { get; set; }
public bool email_verified { get; set; }
public string connection { get; set; }
public string username { get; set; }
public string password { get; set; }

}

}
}


Note: To call /api/v2/users endpoint, you need to have correct permissions (read:users).







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 16:09









Tanver HasanTanver Hasan

34637




34637













  • we use " https://[domain].auth0.com/api/v2/" when , we want to create token , but I have to create user into Aouth0 DB , so that we have to call " https://[domain].auth0.com/api/v2/users" which is reserved API.

    – Satyam Singh
    Nov 28 '18 at 12:09



















  • we use " https://[domain].auth0.com/api/v2/" when , we want to create token , but I have to create user into Aouth0 DB , so that we have to call " https://[domain].auth0.com/api/v2/users" which is reserved API.

    – Satyam Singh
    Nov 28 '18 at 12:09

















we use " https://[domain].auth0.com/api/v2/" when , we want to create token , but I have to create user into Aouth0 DB , so that we have to call " https://[domain].auth0.com/api/v2/users" which is reserved API.

– Satyam Singh
Nov 28 '18 at 12:09





we use " https://[domain].auth0.com/api/v2/" when , we want to create token , but I have to create user into Aouth0 DB , so that we have to call " https://[domain].auth0.com/api/v2/users" which is reserved API.

– Satyam Singh
Nov 28 '18 at 12:09




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53500673%2fauth0-implmentation-with-net-core-2-1%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks