-
Template: microservice
-
Created ABP Studio Version: 0.9.5
-
Current ABP Studio Version: 0.9.21
-
UI Framework: angular
-
Theme: leptonx
-
Theme Style: system
-
Database Provider: ef
-
Database Management System: sqlserver
-
Mobile Framework: maui
-
Public Website: Yes
We have defined the required scopes in the backoffice screen for our application (see the picture below). However, when making an HTTP request to obtain a token using the password grant type, we need to manually specify the scopes in the scope parameter of the token request. Since the scopes are already configured in the backoffice, shouldn’t they be dynamically included in the token request without requiring us to hardcode them in the code? Could you clarify how the scopes defined in the backoffice are intended to be used and whether there is a way to automatically include them in the token request?
public async Task GetTokenAsync(UserLoginInfoDto userLoginInfoDto)
{
var _client = _httpClientFactory.CreateClient();
string tokenUrl = $"{_authServerUrl}/connect/token";
FormUrlEncodedContent tokenRequest = new FormUrlEncodedContent(new[]
{
new KeyValuePair("grant_type","password"),
new KeyValuePair("client_id", _configuration["AccountClient:ClientId"]),
new KeyValuePair("client_secret", _configuration["AccountClient:ClientSecret"]),
new KeyValuePair("username", userLoginInfoDto.UserName),
new KeyValuePair("password", userLoginInfoDto.Password),
new KeyValuePair("scope", " ...SCOPES.... ") //Scopes Added Here
});
HttpResponseMessage response = await _client.PostAsync(tokenUrl, tokenRequest);
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
return !string.IsNullOrWhiteSpace(responseContent) ? JsonConvert.DeserializeObject(responseContent) : throw new Exception(L["EmptyResponse"]);
}
3 Answer(s)
-
0
hi
You can dynamic pass the
scope
parameter dynamically, but you can only pass the scope that defined in backend. -
0
Hi,
Could you please provide more explanation or add more details? Your response is too abstract.
The problem is still persisting, and we need a solution.Regards
-
0
hi
The scope here can be dynamic.
new KeyValuePair("scope", " ...SCOPES.... ") //Scopes Added Here
But the scope value must be defined in your
ClientId
.eg:
myclient
hasAbpAPI profile roles email phone offline_access
scope.You can only pass the scope of
AbpAPI profile roles email phone offline_access
Thanks.