-
Notifications
You must be signed in to change notification settings - Fork 0
Authentication
vhs94 edited this page Apr 1, 2024
·
1 revision
O Client já faz a gestão da autenticação, realizando descriptografia de challenge inclusive. Podemos trabalhar de duas formas:
Este tipo de conexão é o mais comum
- Crie e conecte a instância
var client = new PagSeguroClient(new ClientSettings
{
Token = "<SEU_TOKEN>",
ClientId = "<SEU_CLIENT_ID>",
ClientSecret = "<SEU_CLIENT_SECRET>"
});
await client.ConnectAsync(new AuthorizationCodeWriteDto
{
Code = "<CODIGO_REDIRECIONADO_URL>",
RedirectUri = "<URL_REDIRECIONAMENTO>",
Scope = ApiScopes.ReadAccounts //se omitido, utiliza todos os scopes
});
- Com o client conectado, agora é possível utilizar as APIs autenticadas
var account = await client
.ForAccount()
.GetByIdAsync("accountId");
O Challenge é usado apenas no fluxo de criação de certificados digitais.
- Crie a instância e solicite o challenge
var client = new PagSeguroClient(new ClientSettings
{
Token = "<SEU_TOKEN>",
ClientId = "<SEU_CLIENT_ID>",
ClientSecret = "<SEU_CLIENT_SECRET>",
PrivateKey = "<SUA_PRIVATE_KEY>" // private key usada para descriptografar o challenge
});
await client.ConnectChallengeAsync();
- Com o client conectado, agora é possível criar certificados
await client.ForCertificate().CreateAsync();