Access azure file storage from web app without a backend - azure

Is there a way to access azure storage via Rest Api, using only frontend javascript?
e.g:
User tries to load an image stored in azure storage .
Redirected to portal.azure.com for logging in.
Sent back to my webapp, with the cookies or whatever is needed to generate an authenticated url.

You can authenticate access to Azure blobs using Azure Active Directory.
Then you will be able to get an access token to access azure storage via Rest Api. Here is an example walks you through how to login a user and acquire a token to be used for Microsoft's Graph Api. You can change the Graph Api to storage api.
Updates:
The way to get access token. The scope can be https://storage.azure.com/.default
Access private blob with access token. You also need to add the x-ms-version header.

Related

Download Azure Blob using HTTP Basic Auth using Azure AD Credentials

I have an Azure Storage Account with public access disabled. Inside the storage account are a few Blob Storage Containers. Each container has access managed with AzureAD with varying permissions for each user/group to different Blob Containers.
I want to be able to download items inside the Blob Storage using tools like wget or curl using HTTP Basic Auth or specifying user information in the request.
I'm aware that AzCopy can be used to download Blobs from the containers, but previously we have used http requests to download artifacts and would like to continue using that method.
This question from 2016 Makes it seem like that its possible to do this with Shared Access Signature, which makes me believe that its possible to use with User Delegation SAS, but I have not found a way to set this up, and it requires a lot of parameters, more than a username/password or token.
Does Azure Blob Storage have a way where a user can access blob storage without AzCopy or any other specialized tools and authenticate via a method that does not require additional resources?
No. You must make a separate request for a token to send to Blob.
When a security principal (a user, group, or application) attempts to
access a blob resource, the request must be authorized, unless it is a
blob available for anonymous access. With Azure AD, access to a
resource is a two-step process. First, the security principal's
identity is authenticated and an OAuth 2.0 token is returned. Next,
the token is passed as part of a request to the Blob service and used
by the service to authorize access to the specified resource.
The authentication step requires that an application request an OAuth
2.0 access token at runtime.
Overview of Azure AD for blobs

How to generate an access token for Azure CDN List Rules Engine Endpoint?

I have subscribed to Premium Verizon Plan of Azure CDN Service. With that I gained access to the Azure CDN Policy Rules Portal wherein I am able to manage all of the rules pertaining to the CDN Service I have subscribed to.
As part of the compliance program that I am working with as of the moment, I wanted to list all of the available Policies within my CDN Service using this endpoint:
https://cdn.windowsazure.com/api/v3/rules-engine/v1.0/policies?page_size=20&platform_id=http-large&policy_type=customer&sort=-created_at&state=locked
My currently problem is that I am unable to generate the access token needed to call the endpoint successfully. As of the moment here are the methods that I have currently used to generate access token for the endpoint:
Generate the Access Token using the Client Credentials from the Identity Dashboard:
I have successfully generated the Access Token from this step but I
am unable to see the necessary scope ("ec.rules") needed to call the
API Endpoint. Source
Document
Using the Token from the Azure CDN Policy Rules Portal:
I am unable to find the "Generate New Primary" button stated in the Source Document
To configure Token authentication & generate tokens on Azure CDN Premium from Verizon, you can follow the steps on this document:
https://learn.microsoft.com/en-us/azure/cdn/cdn-token-auth#setting-up-token-authentication

Restrict Azure CDN downloads to Azure Active Directory Clients

We want to restrict file downloads from Azure CDN to instances of a given tool. These tools already have an ADFS client which is currently used to get a bearer token to authenticate the client with an API housed in DataPower. I want to create an Azure AD group, assign the clients client-ids/secrets within this group, and restrict READ access to CDN files to this group so that they can get a bearer token and access the resource.
Is there a pre-existing pattern to restrict Read access in this manner?
Your application can have authorization decision to provide read access to CDN resources.
Kindly go through the document to get detailed explanation.

Get access to Azure Blob storage and Key Vault from Azure ad B2C account

i'm new in Azure. And if the question is stupid don't punish me.
I made an App in Azure to get access to storage blob and key vault.
I used Azure AD tenant(with AD users) and user_impersonation scopes like https://storage.azure.com/user_impersonation and https://vault.azure.net/user_impersonation
All I need from that App is:
Upload file to Blob
Download file from Blob
Delete file from Blob
Generate SAS
Get value of secret from Key Vault.
In Azure AD tenant it works fine. I can request to login.microsoftonline.com enter credentials and get token to my back-end to do all this things listed above.But later customer desided to use custom UX(to hide Microsoft login page) and only one way to get this is to use B2C and local accounts.
I made a B2C tenant like here tutorial-create-tenant
Registered App like here tutorial-register-applications and add Api permissions to Azure Storage from APIs my organization uses tab
Created user-flows like here user-flows
All local users in one group with Owner policy
Using this request i got a token
https:/<domain_name>.b2clogin.com/<domain_name>.onmicrosoft.com/oauth2/v2.0/authorize?
p=B2C_1_signin&
client_id=<App_ID>&
nonce=defaultNonce&
redirect_uri=https%3A%2F%2Fjwt.ms%2F& // https://jwt.ms/
scope=https%3A%2F%2Fstorage.azure.com%2Fuser_impersonation& // https://storage.azure.com/user_impersonation
response_type=token&
prompt=login
In decoded token claim "aud" has id the same as Azure Storage API from APIs my organization uses tab when I register App, "scp" is "user_impersonation". But using this token i can't get access to storage using Postman (I use it as Bearer token)
For example GET request to https://.blob.core.windows.net/?comp=list must return json with list of containers(and in Azure AD it work) but with this token got an error
<Error>
<Code>AuthenticationFailed</Code>
<Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:49873755-401e-0065-0dd0-386211000000
Time:2020-06-02T11:24:57.3079213Z</Message>
<AuthenticationErrorDetail>Signature validation failed. Signature key not found.</AuthenticationErrorDetail>
</Error>
May be I need to add additional Api access to Storage app some how?
What should I set up yet?
Or maybe there is a way to connect Ad B2C tenant to AD tenant?
Will appreciate any help.
Upd: as #juunas noiced I had differernt subscriptions for B2C tenant and Storage account. Now b2c and storage in one sub(i created new b2c, link subscription and move it inside b2c tenant, after that i made a storage account in moved subscription)
But the problem still exist.
I tried to change scope in request. On Api Permissions page in Azure Storage user_impersonation option you can see link like
https://*.dfs.core.windows.net/user_impersonation
when I used this link as a scope I've got an error
AADB2C90117: The scope
'https://*.dfs.core.windows.net/user_impersonation'
provided in the request is not supported.
After replacing of asterisk by name of storage account in link I've got the next message
AADB2C90205: This application does not have sufficient permissions
against this web resource to perform the operation.
It looks like I need to get additional permissions for App?
Does it make sense? Or trying to get access to particular storage account is wrong?

Write to Azure Blob with username and password

I need to write to an azure blob store using my app that is running on a customer's network. I would like to use a network username and password to secure the blob location. I have been reading MANY articles but I cannot see how to use a username and password to connect to the azure blob store.
It is a WPF app, so I do not want to store my key (or any secrets) in a config file or hard code it as it will be too easy to get with a decompiler. I would prefer to issue the user with a network username and password. That way I can change the password or disable the username when needed.
Can anyone point me in the right direction here please, I just keep looping back to the same documentation over and over
There are three ways to get connected to Azure Storage:
Using account name/key
Using Azure Active Directory (Azure AD) authentication
Using Shared Access Signature
1st option is automatically ruled out as you don't want to store the secrets in the application (wise decision BTW).
You can use Azure AD authentication to connect to Blob Storage. Your users would need to be present in Azure AD for this though. Whenever a user launches your application, you will redirect them to Azure AD for authentication and once they are authenticated, they will be able to use the application. You can read more about it here: https://learn.microsoft.com/en-us/azure/storage/common/storage-auth-aad
3rd option is to use Shared Access Signature (SAS) which basically is a URL that has a time-bound/permission driven access to your storage. The way this would work is that your application will authenticate the users by asking them to provide their network username/password. Once they are authenticated, they will get access to the application. In the application, you can make a call to an API that will return a SAS URL using which a user will be able to upload data into blob storage. You can read more about it here: https://learn.microsoft.com/en-us/azure/storage/common/storage-sas-overview?toc=%2fazure%2fstorage%2fblobs%2ftoc.json

Resources