Monthly Archives: %sJuly 2014

Opinionated AngularJS styleguide for teams

Excellent article explaining different styles of writing angularjs modules, controllers: http://toddmotto.com/opinionated-angular-js-styleguide-for-teams/

By |July 24th, 2014|Coding|0 Comments

Using Azure Powershell to start and stop a VM

Using an Azure VM is a convenient way to test new software without having to corrupt your own terminal or using more resources for a virtual instance using Virtual Box, VMWare, etc.

As you may already know if a VM is stopped there are no charges for computing cost. However you will still incur a charge for the storage used by the VM (which is significantly less). Using a powershell script to manage the state of these VMs are helpful. I have the shutdown powershell script on a scheduler that runs nightly.

In order to use azure powershell you must do the following:

  • Install Azure PowerShell.
  • Connect to your subscription within Azure Powershell

Fortunately Microsoft has documented this process in an article located at: http://azure.microsoft.com/en-us/documentation/articles/install-configure-powershell

After installing feel free to try the following code (make sure to replace “MY_COMPUTER” with the name of your VM:

Start-AzureVM -ServiceName "MY_COMPUTER" -Name "MY_COMPUTER"

Stop-AzureVM -ServiceName "MY_COMPUTER" -Name "MY_COMPUTER" -Force
By |July 16th, 2014|Coding|0 Comments

Generating a certificate and private key using openssl

Sometimes you need to generate a quick certificate to test your app. Using openssl you can easily accomplish this, take a look at my example below:

# Generate Cert and Key in seperate file
# Provide the .cert to the end user
openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 -keyout QA.key -out QA.cert
 
# Merge cert and private key to make a p12 file, this file will be used by .NET's X509Certificate2 class, The private key will be accessible via the "PrivateKey" property
openssl pkcs12 -export -in qa.cert -inkey qa.key -out qa.p12 -name "QA"

Got a question? Send me a message on twitter: @tekguy

By |July 8th, 2014|Coding|0 Comments

Logging off WS-Federation by creating a wsignout1.0 message

Recently I integrated my web app with Azure ACS but was having a difficult time signing out of ACS (deleting my cookie off the .accesscontrol.windows.net server). The following code will create a wsignout1.0 message. Essentially it will construct a url with the action parameter set to “wsignout1.0”. An additional parameter “wreply” allows you to specify a url to redirect to after you have been signed out:

public ActionResult LogOff()
{
    // Load Identity Configuration
    FederationConfiguration config = FederatedAuthentication.FederationConfiguration;
 
    // Get wtrealm from WsFederationConfiguation Section
    string wtrealm = config.WsFederationConfiguration.Realm;
    string wreply;
 
    // Construct wreply value from wtrealm (This will be the return URL to your app)
    wreply = wtrealm;
 
    // Read the ACS Ws-Federation endpoint from web.Config
    // something like "https://<your-namespace>.accesscontrol.windows.net/v2/wsfederation"
    string wsFederationEndpoint = ConfigurationManager.AppSettings["ida:Issuer"];
 
    SignOutRequestMessage signoutRequestMessage = new SignOutRequestMessage(new Uri(wsFederationEndpoint));
 
    signoutRequestMessage.Parameters.Add("wreply", wreply);
    signoutRequestMessage.Parameters.Add("wtrealm", wtrealm);
 
    FederatedAuthentication.SessionAuthenticationModule.SignOut();
 
    string signoutUrl = signoutRequestMessage.WriteQueryString();
 
    return this.Redirect(signoutUrl);
}

Got a question? Send me a message on twitter: @tekguy

By |July 5th, 2014|Coding|0 Comments