📝 Passo 3: Exemplos Práticos de Autenticação
Nos exemplos de código abaixo, substitua os seguintes valores pelos seus dados reais:
SEU_CLIENT_ID→ Seu Client ID recebidoSEU_CLIENT_SECRET→ Seu Client Secret recebidousuario@exemplo.com→ Credenciais de usuário (quando aplicável)
As URLs mostradas nesta página são apenas exemplos ilustrativos.
Você DEVE substituir pelas URLs corretas que recebeu no e-mail da Credsystem:
- URL do Red Hat SSO/Keycloak (ex:
https://ssohml.credsystem.com.br/auth/realms/SEU_REALM/...) - URL do Oracle IDCS (se aplicável)
- Realm, scope e outros parâmetros específicos da sua integração
As URLs variam conforme a parceria e ambiente (homologação/produção).
🚀 Teste Rápido com cURL
Antes de implementar no seu código, teste suas credenciais com cURL:
As URLs abaixo são exemplos. Use as URLs reais que você recebeu no e-mail da Credsystem (realm, ambiente, scope, etc.).
Red Hat SSO (Keycloak) - Client Credentials
# Ambiente: Homologação
curl -X POST "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=SEU_CLIENT_ID" \
-d "client_secret=SEU_CLIENT_SECRET"
Oracle IDCS - Client Credentials
# Gere o Basic Auth primeiro (client_id:client_secret em Base64)
echo -n "SEU_CLIENT_ID:SEU_CLIENT_SECRET" | base64
# Use o resultado no header Authorization
curl -X POST "https://idcs-0fe1bec59571471484a8896c1a0d7a62.identity.oraclecloud.com/oauth2/v1/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic SEU_BASE64_AQUI" \
-d "grant_type=client_credentials" \
-d "scope=SEU_SCOPE"
Se as credenciais estiverem corretas, você receberá:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cC...",
"token_type": "Bearer",
"expires_in": 300
}
📚 Métodos de Autenticação
🔑 1. Red Hat SSO - Client Credentials
Quando usar: Integrações servidor-a-servidor (backend), jobs automatizados, microserviços.
Retorno: access_token, token_type, expires_in
- cURL
- JavaScript
- Python
- Java
- C#
- PHP
- Go
curl -X POST "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=SEU_CLIENT_ID" \
-d "client_secret=SEU_CLIENT_SECRET"
const getAccessToken = async () => {
const response = await fetch(
'https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: 'SEU_CLIENT_ID',
client_secret: 'SEU_CLIENT_SECRET',
}),
}
);
const data = await response.json();
return data.access_token;
};
import requests
def get_access_token():
url = "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token"
payload = {
'grant_type': 'client_credentials',
'client_id': 'SEU_CLIENT_ID',
'client_secret': 'SEU_CLIENT_SECRET'
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.post(url, data=payload, headers=headers)
return response.json()['access_token']
import java.net.http.*;
import java.net.URI;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class CredsystemAuth {
public static String getAccessToken() throws Exception {
HttpClient client = HttpClient.newHttpClient();
String body = "grant_type=client_credentials" +
"&client_id=SEU_CLIENT_ID" +
"&client_secret=SEU_CLIENT_SECRET";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token"))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
JsonObject jsonObject = JsonParser.parseString(response.body()).getAsJsonObject();
return jsonObject.get("access_token").getAsString();
}
}
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
public class CredsystemAuth
{
private static readonly HttpClient client = new HttpClient();
public static async Task<string> GetAccessToken()
{
var values = new Dictionary<string, string>
{
{ "grant_type", "client_credentials" },
{ "client_id", "SEU_CLIENT_ID" },
{ "client_secret", "SEU_CLIENT_SECRET" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(
"https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token",
content
);
var responseString = await response.Content.ReadAsStringAsync();
var jsonDoc = JsonDocument.Parse(responseString);
return jsonDoc.RootElement.GetProperty("access_token").GetString();
}
}
<?php
function getAccessToken() {
$url = "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token";
$data = array(
'grant_type' => 'client_credentials',
'client_id' => 'SEU_CLIENT_ID',
'client_secret' => 'SEU_CLIENT_SECRET'
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);
return $response['access_token'];
}
?>
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
)
type TokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
}
func getAccessToken() (string, error) {
authURL := "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token"
data := url.Values{}
data.Set("grant_type", "client_credentials")
data.Set("client_id", "SEU_CLIENT_ID")
data.Set("client_secret", "SEU_CLIENT_SECRET")
req, err := http.NewRequest("POST", authURL, bytes.NewBufferString(data.Encode()))
if err != nil {
return "", err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
var tokenResp TokenResponse
if err := json.Unmarshal(body, &tokenResp); err != nil {
return "", err
}
return tokenResp.AccessToken, nil
}
👤 2. Red Hat SSO - Password Grant
Quando usar: Aplicações web com login de usuário, apps móveis.
Retorno: access_token, refresh_token, expires_in, refresh_expires_in, scope, session_state
- cURL
- JavaScript
- Python
- Java
- C#
- PHP
- Go
curl -X POST "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=password" \
-d "client_id=SEU_CLIENT_ID" \
-d "client_secret=SEU_CLIENT_SECRET" \
-d "username=usuario@exemplo.com" \
-d "password=SenhaSegura123!" \
-d "scope=openid profile email"
const authenticateUser = async (username, password) => {
const response = await fetch(
'https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
grant_type: 'password',
client_id: 'SEU_CLIENT_ID',
client_secret: 'SEU_CLIENT_SECRET',
username: username,
password: password,
scope: 'openid profile email'
}),
}
);
const data = await response.json();
return {
accessToken: data.access_token,
refreshToken: data.refresh_token,
expiresIn: data.expires_in
};
};
import requests
def authenticate_user(username, password):
url = "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token"
payload = {
'grant_type': 'password',
'client_id': 'SEU_CLIENT_ID',
'client_secret': 'SEU_CLIENT_SECRET',
'username': username,
'password': password,
'scope': 'openid profile email'
}
response = requests.post(url, data=payload)
data = response.json()
return {
'access_token': data['access_token'],
'refresh_token': data['refresh_token'],
'expires_in': data['expires_in']
}
import java.net.http.*;
import java.net.URI;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class PasswordGrantAuth {
public static JsonObject authenticateUser(String username, String password) throws Exception {
HttpClient client = HttpClient.newHttpClient();
String body = "grant_type=password" +
"&client_id=SEU_CLIENT_ID" +
"&client_secret=SEU_CLIENT_SECRET" +
"&username=" + username +
"&password=" + password +
"&scope=openid profile email";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token"))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
return JsonParser.parseString(response.body()).getAsJsonObject();
}
}
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
public class PasswordGrantAuth
{
public static async Task<JsonDocument> AuthenticateUser(string username, string password)
{
var client = new HttpClient();
var values = new Dictionary<string, string>
{
{ "grant_type", "password" },
{ "client_id", "SEU_CLIENT_ID" },
{ "client_secret", "SEU_CLIENT_SECRET" },
{ "username", username },
{ "password", password },
{ "scope", "openid profile email" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(
"https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token",
content
);
var responseString = await response.Content.ReadAsStringAsync();
return JsonDocument.Parse(responseString);
}
}
<?php
function authenticateUser($username, $password) {
$url = "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token";
$data = array(
'grant_type' => 'password',
'client_id' => 'SEU_CLIENT_ID',
'client_secret' => 'SEU_CLIENT_SECRET',
'username' => $username,
'password' => $password,
'scope' => 'openid profile email'
);
$options = array(
'http' => array(
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return json_decode($result, true);
}
?>
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
)
type AuthResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
}
func AuthenticateUser(username, password string) (*AuthResponse, error) {
authURL := "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token"
data := url.Values{}
data.Set("grant_type", "password")
data.Set("client_id", "SEU_CLIENT_ID")
data.Set("client_secret", "SEU_CLIENT_SECRET")
data.Set("username", username)
data.Set("password", password)
data.Set("scope", "openid profile email")
req, _ := http.NewRequest("POST", authURL, bytes.NewBufferString(data.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var authResp AuthResponse
json.Unmarshal(body, &authResp)
return &authResp, nil
}
🔄 3. Red Hat SSO - Refresh Token
Quando usar: Renovar token expirado sem autenticar novamente.
Requer: refresh_token válido do Password Grant
Retorno: Novo access_token, refresh_token, expires_in
- cURL
- JavaScript
- Python
- Java
- C#
- PHP
- Go
curl -X POST "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token" \
-d "client_id=SEU_CLIENT_ID" \
-d "client_secret=SEU_CLIENT_SECRET" \
-d "refresh_token=SEU_REFRESH_TOKEN"
const refreshAccessToken = async (refreshToken) => {
const response = await fetch(
'https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
grant_type: 'refresh_token',
client_id: 'SEU_CLIENT_ID',
client_secret: 'SEU_CLIENT_SECRET',
refresh_token: refreshToken
}),
}
);
const data = await response.json();
return {
accessToken: data.access_token,
refreshToken: data.refresh_token,
expiresIn: data.expires_in
};
};
import requests
def refresh_access_token(refresh_token):
url = "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token"
payload = {
'grant_type': 'refresh_token',
'client_id': 'SEU_CLIENT_ID',
'client_secret': 'SEU_CLIENT_SECRET',
'refresh_token': refresh_token
}
response = requests.post(url, data=payload)
data = response.json()
return {
'access_token': data['access_token'],
'refresh_token': data['refresh_token'],
'expires_in': data['expires_in']
}
import java.net.http.*;
import java.net.URI;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class RefreshTokenAuth {
public static JsonObject refreshAccessToken(String refreshToken) throws Exception {
HttpClient client = HttpClient.newHttpClient();
String body = "grant_type=refresh_token" +
"&client_id=SEU_CLIENT_ID" +
"&client_secret=SEU_CLIENT_SECRET" +
"&refresh_token=" + refreshToken;
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token"))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
return JsonParser.parseString(response.body()).getAsJsonObject();
}
}
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
public class RefreshTokenAuth
{
public static async Task<JsonDocument> RefreshAccessToken(string refreshToken)
{
var client = new HttpClient();
var values = new Dictionary<string, string>
{
{ "grant_type", "refresh_token" },
{ "client_id", "SEU_CLIENT_ID" },
{ "client_secret", "SEU_CLIENT_SECRET" },
{ "refresh_token", refreshToken }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(
"https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token",
content
);
var responseString = await response.Content.ReadAsStringAsync();
return JsonDocument.Parse(responseString);
}
}
<?php
function refreshAccessToken($refreshToken) {
$url = "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token";
$data = array(
'grant_type' => 'refresh_token',
'client_id' => 'SEU_CLIENT_ID',
'client_secret' => 'SEU_CLIENT_SECRET',
'refresh_token' => $refreshToken
);
$options = array(
'http' => array(
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return json_decode($result, true);
}
?>
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
)
type RefreshResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
}
func RefreshAccessToken(refreshToken string) (*RefreshResponse, error) {
authURL := "https://ssohml.credsystem.com.br/auth/realms/exemplo123/protocol/openid-connect/token"
data := url.Values{}
data.Set("grant_type", "refresh_token")
data.Set("client_id", "SEU_CLIENT_ID")
data.Set("client_secret", "SEU_CLIENT_SECRET")
data.Set("refresh_token", refreshToken)
req, _ := http.NewRequest("POST", authURL, bytes.NewBufferString(data.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var refreshResp RefreshResponse
json.Unmarshal(body, &refreshResp)
return &refreshResp, nil
}
🏢 4. Oracle IDCS - Client Credentials
Quando usar: Integrações servidor-a-servidor (backend), jobs automatizados, microserviços.
Requer: Basic Auth (client_id:client_secret em Base64) + scope específico da loja
Retorno: access_token, token_type, expires_in
- cURL
- JavaScript
- Python
- Java
- C#
- PHP
- Go
# Exemplo para LOJA-A
curl -X POST "https://idcs-0fe1bec59571471484a8896c1a0d7a62.identity.oraclecloud.com/oauth2/v1/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic BASE64_CLIENT_ID_SECRET" \
-d "grant_type=client_credentials" \
-d "scope=LOJA-A-HML-cc3e9c9b-7d64-4ff3-a86a-1d7teste19ac13"
O header Authorization: Basic deve conter client_id:client_secret em Base64:
echo -n "client_id:client_secret" | base64
const getIDCSToken = async (clientId, clientSecret, scope) => {
const basicAuth = btoa(`${clientId}:${clientSecret}`);
const response = await fetch(
'https://idcs-0fe1bec59571471484a8896c1a0d7a62.identity.oraclecloud.com/oauth2/v1/token',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${basicAuth}`
},
body: new URLSearchParams({
grant_type: 'client_credentials',
scope: scope
}),
}
);
const data = await response.json();
return data.access_token;
};
// Exemplo de uso
const token = await getIDCSToken(
'SEU_CLIENT_ID',
'SEU_CLIENT_SECRET',
'LOJA-A-HML-cc3e9c9b-7d64-4ff3-a86a-1d7teste19ac13'
);
import requests
import base64
def get_idcs_token(client_id, client_secret, scope):
url = "https://idcs-0fe1bec59571471484a8896c1a0d7a62.identity.oraclecloud.com/oauth2/v1/token"
# Gerar Basic Auth
credentials = f"{client_id}:{client_secret}"
basic_auth = base64.b64encode(credentials.encode()).decode()
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': f'Basic {basic_auth}'
}
payload = {
'grant_type': 'client_credentials',
'scope': scope
}
response = requests.post(url, data=payload, headers=headers)
return response.json()['access_token']
# Exemplo de uso
token = get_idcs_token(
'SEU_CLIENT_ID',
'SEU_CLIENT_SECRET',
'LOJA-A-HML-cc3e9c9b-7d64-4ff3-a86a-1d7teste19ac13'
)
import java.net.http.*;
import java.net.URI;
import java.util.Base64;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class OracleIDCSAuth {
public static String getIDCSToken(String clientId, String clientSecret, String scope) throws Exception {
HttpClient client = HttpClient.newHttpClient();
// Gerar Basic Auth
String credentials = clientId + ":" + clientSecret;
String basicAuth = Base64.getEncoder().encodeToString(credentials.getBytes());
String body = "grant_type=client_credentials&scope=" + scope;
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://idcs-0fe1bec59571471484a8896c1a0d7a62.identity.oraclecloud.com/oauth2/v1/token"))
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Authorization", "Basic " + basicAuth)
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
JsonObject jsonObject = JsonParser.parseString(response.body()).getAsJsonObject();
return jsonObject.get("access_token").getAsString();
}
}
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class OracleIDCSAuth
{
public static async Task<string> GetIDCSToken(string clientId, string clientSecret, string scope)
{
var client = new HttpClient();
// Gerar Basic Auth
var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}"));
client.DefaultRequestHeaders.Add("Authorization", $"Basic {credentials}");
var values = new Dictionary<string, string>
{
{ "grant_type", "client_credentials" },
{ "scope", scope }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(
"https://idcs-0fe1bec59571471484a8896c1a0d7a62.identity.oraclecloud.com/oauth2/v1/token",
content
);
var responseString = await response.Content.ReadAsStringAsync();
var jsonDoc = JsonDocument.Parse(responseString);
return jsonDoc.RootElement.GetProperty("access_token").GetString();
}
}
<?php
function getIDCSToken($clientId, $clientSecret, $scope) {
$url = "https://idcs-0fe1bec59571471484a8896c1a0d7a62.identity.oraclecloud.com/oauth2/v1/token";
// Gerar Basic Auth
$credentials = base64_encode($clientId . ':' . $clientSecret);
$data = array(
'grant_type' => 'client_credentials',
'scope' => $scope
);
$options = array(
'http' => array(
'header' => "Content-Type: application/x-www-form-urlencoded\r\n" .
"Authorization: Basic " . $credentials . "\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);
return $response['access_token'];
}
// Exemplo de uso
$token = getIDCSToken(
'SEU_CLIENT_ID',
'SEU_CLIENT_SECRET',
'LOJA-A-HML-cc3e9c9b-7d64-4ff3-a86a-1d7teste19ac13'
);
?>
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
)
type IDCSTokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
}
func GetIDCSToken(clientId, clientSecret, scope string) (string, error) {
idcsURL := "https://idcs-0fe1bec59571471484a8896c1a0d7a62.identity.oraclecloud.com/oauth2/v1/token"
// Gerar Basic Auth
credentials := clientId + ":" + clientSecret
basicAuth := base64.StdEncoding.EncodeToString([]byte(credentials))
data := url.Values{}
data.Set("grant_type", "client_credentials")
data.Set("scope", scope)
req, err := http.NewRequest("POST", idcsURL, bytes.NewBufferString(data.Encode()))
if err != nil {
return "", err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Authorization", "Basic "+basicAuth)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
var tokenResp IDCSTokenResponse
if err := json.Unmarshal(body, &tokenResp); err != nil {
return "", err
}
return tokenResp.AccessToken, nil
}
🎯 Próximo Passo
Agora que você tem exemplos práticos de autenticação, veja como usar o token:
👉 Passo 4: Usando o Token nas Requisições
Ou volte para o Índice de Autenticação