Skip to content

A small Swift library to help with the generation of SAS tokens for use in Azure

Notifications You must be signed in to change notification settings

mannie/AzureCocoaSAS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AzureCocoaSAS

This is a small Swift library to help with the generation of SAS tokens for use in Azure.

Create a Demo Project

  1. Using the command line interface, type in the following commands to:

    1. Create a new directory.
    2. Navigate into that new folder.
    3. Create a new Swift project.
    mkdir Demo
    cd Demo
    swift package init --type executable
  2. Open the newly created Package.swift file (./Package.swift) and edit it to contain the following:

    import PackageDescription
    
    let package = Package(
        name: "Demo",
        dependencies: [
            .package(url: "https://github.com/mannie/AzureCocoaSAS.git", .branch("master"))
        ],
        targets: [
            .target(name: "Demo", dependencies: [ "AzureCocoaSAS" ]),
            .testTarget(name: "DemoTests", dependencies: ["Demo"]),
        ]
    )
  3. Open the main.swift file (./Sources/Demo/main.swift) and edit it to contain the following or similar:

    import AzureCocoaSAS
    
    let policy = AzureCocoaSAS.SharedAccessPolicy(name: "SharedAccessKey", key: "Jp9cUB1iCF=")
    let endpoint = "https://divergent.servicebus.windows.net/streamer"
    
    let t1 = try? AzureCocoaSAS.token(for: endpoint, using: policy) // defaults to a lifetinme of 1 week
    let t2 = try? AzureCocoaSAS.token(for: endpoint, using: policy, lifetime: 60 * 60) // lifetime of 1 hour
    
    print("t1 => \(t1!)")
    print("t2 => \(t2!)")
  4. Using the command line prompt, run your Swift app:

    swift run

    Your app should output something similar to:

    t1 => SharedAccessSignature sr=https%3A%2F%2Fdivergent%2Eservicebus%2Ewindows%2Enet%2Fstreamer&sig=JFbf9AXbrbqTFlEIioNe%2F36OeKC8QNKMcEAnjmKRo%2BU%3D&se=1551309021&skn=SharedAccessKey
    t2 => SharedAccessSignature sr=https%3A%2F%2Fdivergent%2Eservicebus%2Ewindows%2Enet%2Fstreamer&sig=1dguWqPExRoXy9rwZg%2B5OdpVirOkQEBtZkk0tMTSU%2Fo%3D&se=1550707821&skn=SharedAccessKey

Running Unit Tests

Use CLI to run:
```sh
swift test
```
Output:
```
[1/3] Compiling Swift Module 'AzureCocoaSAS' (1 sources)
Test Suite 'All tests' started at 2019-05-23 12:16:19.078
Test Suite 'AzureCocoaSASPackageTests.xctest' started at 2019-05-23 12:16:19.078
Test Suite 'AzureCocoaSASTests' started at 2019-05-23 12:16:19.078
Test Case '-[AzureCocoaSASTests.AzureCocoaSASTests testBasic]' started.
Test Case '-[AzureCocoaSASTests.AzureCocoaSASTests testBasic]' passed (0.150 seconds).
Test Suite 'AzureCocoaSASTests' passed at 2019-05-23 12:16:19.228.
Executed 1 test, with 0 failures (0 unexpected) in 0.150 (0.150) seconds
Test Suite 'AzureCocoaSASPackageTests.xctest' passed at 2019-05-23 12:16:19.228.
Executed 1 test, with 0 failures (0 unexpected) in 0.150 (0.150) seconds
Test Suite 'All tests' passed at 2019-05-23 12:16:19.228.
Executed 1 test, with 0 failures (0 unexpected) in 0.150 (0.151) seconds 
```

Sample Projects

About

A small Swift library to help with the generation of SAS tokens for use in Azure

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages