Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudBlockBlob generated a wrong SAS token #73

Open
Sleepingbug opened this issue Nov 8, 2018 · 0 comments
Open

CloudBlockBlob generated a wrong SAS token #73

Sleepingbug opened this issue Nov 8, 2018 · 0 comments

Comments

@Sleepingbug
Copy link

first of all, I can upload files to Azure Blob Storage Service.
I'm try to generate SAS URL but failed.

static String generateBlobUrl( CloudBlockBlob blob ){

    Log.v("Test",generateBlobUrl--begin--");
    try {
        SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();

        EnumSet aSet = EnumSet.noneOf( SharedAccessAccountPermissions.class );
        aSet.add( SharedAccessAccountPermissions.READ );
        aSet.add( SharedAccessAccountPermissions.WRITE );
        aSet.add( SharedAccessAccountPermissions.LIST );
        policy.setPermissions( aSet );

        GregorianCalendar calendar = new GregorianCalendar( TimeZone.getTimeZone("UTC"));
        calendar.setTime(new Date());
        policy.setSharedAccessStartTime(calendar.getTime());
        calendar.add( Calendar.HOUR, 24);
        policy.setSharedAccessExpiryTime(calendar.getTime());


        String sasToken = blob.generateSharedAccessSignature(policy, null );
        String host = "https://mystorage.blob.core.windows.net/"+ blob.getContainer().getName() +"/"+ blob.getName();
        String url = host +"?"+ sasToken;
        Log.v("Test",generateBlobUrl========sasToken="+ sasToken );
        Log.v("Test",generateBlobUrl========host="+ host );
        Log.v("Test",generateBlobUrl========url="+ url );
        return url;
    }
    catch ( Exception e){
        e.printStackTrace();
        Log.v("Test",generateBlobUrl--error=" + e.getLocalizedMessage() );
    }

    return null;
}

1, sasToken is wrong.
log: sasToken=sig=GMqjezkLl1MSAqTyybfweB0hKvD3B5qhK9Q2ihhJefA%3D&st=2018-11-08T09%3A10%3A14Z&se=2018-11-09T09%3A10%3A14Z&sv=2017-04-17&sr=b

  1. datetime format is wrong.
  2. there is no "spr=https" in this sasToken

2, url is wrong too.
log: url=https://mystorage.blob.core.windows.net/d89ad74fbfd74ea5969da0f5588e387b/AIRecord/20181108170953_audio.wav?sig=GMqjezkLl1MSAqTyybfweB0hKvD3B5qhK9Q2ihhJefA%3D&st=2018-11-08T09%3A10%3A14Z&se=2018-11-09T09%3A10%3A14Z&sv=2017-04-17&sr=b

when i try download from this url, i see this error:

AuthenticationFailed Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:d60e6e38-801e-00d3-3047-778133000000 Time:2018-11-08T09:45:58.9178592Z sp is mandatory. Cannot be empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant