React Native
React Native
Configure Azure SAS Authentication for REST
See more REST Examples
Demonstrates Rest.SetAuthAzureSas, which associates an AuthAzureSAS provider so requests are authorized with an Azure Shared Access Signature token.
Background. A SAS token grants time-limited, permission-scoped access to Azure Storage resources without exposing the account key on the wire. Use SAS authorization when a query-token approach is preferred over Shared Key headers.
Chilkat React Native Downloads
import { AuthAzureSAS, Rest } from '@chilkat/react-native'
async function chilkatExample() {
const rest = new Rest();
const bTls = true;
const bAutoReconnect = true;
try {
await rest.connectAsync('example.com', 443, bTls, bAutoReconnect);
} catch {
console.log(rest.lastErrorText);
return;
}
// Configure Azure Shared Access Signature (SAS) authentication. Provide the account access key
// and the SAS token query parameters; Chilkat adds the SAS token to each request.
const azSas = new AuthAzureSAS();
// Normally you would not hard-code secrets in source. You should instead obtain them from an
// interactive prompt, environment variable, or a secrets vault.
azSas.accessKey = 'BASE64_ACCOUNT_ACCESS_KEY';
// Associate the provider with the REST object.
try {
rest.setAuthAzureSas(azSas);
} catch {
console.log(rest.lastErrorText);
return;
}
let responseText: string;
try {
responseText = await rest.fullRequestNoBodyAsync('GET', '/mycontainer/myblob.txt');
} catch {
console.log(rest.lastErrorText);
return;
}
console.log(responseText);
}