Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Mar 11, 2018
1 parent ca0127a commit d9f647f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 101 deletions.
22 changes: 0 additions & 22 deletions GettingStarted.txt

This file was deleted.

87 changes: 13 additions & 74 deletions ReadMe.md
@@ -1,88 +1,27 @@
# AppCenter.DemoApp

This project was created using the Prism QuickStart Templates by Dan Siegel. Be sure
to follow Dan on Twitter @DanJSiegel.
This project was created using the Prism Template Studio & Developer Toolkit by Dan Siegel. Be sure to follow Dan on Twitter [@DanJSiegel](https://twitter.com/DanJSiegel). This app is meant as a demo to show how to secure your application code. You will notice that there is no `Info.plist` or `AndroidManifest.xml` in the iOS and Android projects. Both of these files instead exist as tokenized templates in the build folder. There are also no hard coded values for the AppCenter application secrets.

## Developer Notes
The [Mobile.BuildTools](https://github.com/dansiegel/Mobile.BuildTools) is able to handle these tasks easily for you. This project is using all of the defaults, however it is all configurable and customizable to allow you to inject secrets at build across multiple projects in a single solution, enable debugging output, and more.

This Project uses Mobile.BuildTools to inject sensitive variables at build time.
After cloning this repository you will need to make sure that you have taken some
time to do some basic setup in your environment prior to building.
## Getting the application to build locally

### Application Secrets
After cloning this repository to your local machine be sure to copy and rename the tokenized manifests from the build folder to the appropriate location.

Every application contains sensitive information that should never be checked into
source control. In order to handle this the Mobile.BuildTools looks for a file in
the project named `secrets.json`. If the file exists it will generate a new file
`Helpers/Secrets.cs` with the values from your json file. Be sure to update this ReadMe
with any Key values that get added over time so that other developers can add this
for local builds.
**WARNING:** Android will automatically create a default AndroidManifest if you open Visual Studio or attempt to build before you have copied the template. For the purposes of this demo we don't actually require any tokens to be replaced for our Android build, however we do have a permission defined that will not be included in an auto generated Manifest. Be sure to replace the tokens with the appropriate values from AppCenter for your Info.plist.

Next create a file named `secrets.json` in the AppCenter.DemoApp project, and update it to look like the following:

```json
{
"AppCenter_iOS_Secret": "{App Center Secret}",
"AppCenter_Android_Secret": "{App Center Secret}",
"AppServiceEndpoint": "{Backend API URI}"
"AppCenter_iOS_Secret": "{Your AppCenter iOS Application Secret HERE}",
"AppCenter_Android_Secret": "{Your AppCenter Android Application Secret HERE}",
"AppServiceEndpoint": "https://demo.contoso.com/"
}
```

#### Build Server Secrets

Because `secrets.json` does not exist within the checked in code and `Helpers/Secrets.cs`
is also not checked in, the Build Server must generate the `secrets.json` as part of the
build. This is done automatically by including prefixed Environmental variables in the
build. For instance the secret for `AppCenter_iOS_Secret` would be added as
`Secret_AppCenter_iOS_Secret` to the build environment. You can additionally add
platform specific secrets that are not compiled as part of the shared code by using
the following Prefix Matrix:

| Platform | Secrets Prefix |
| -------- | -------------- |
| Android | DroidSecret_ |
| iOS | iOSSecret_ |
| UWP | UWPSecret_ |
| macOS | MacSecret_ |
| Tizen | TizenSecret_ |
| Default | Secret_ |

If you need to inject secrets into multiple shared libraries that are part of the same
solution you can do this by adding an override value for `BuildHostSecretPrefix` in
the PropertyGroup of your CSProj like:

```xml
<Project>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<BuildHostSecretPrefix>MyCustomPrefix_</BuildHostSecretPrefix>
</PropertyGroup>
</Project>
```

### Application Manifests

The Mobile.BuildTools also helps with protecting Application Secrets that may be
contained within Application Manifests like `AndroidManifest.xml` or `Info.plist`.
Contained within the build directory are templates for these manifests which are
not checked into Source Control.

#### Developer Setup

The Manifest templates should be copied from the build directory to the appropriate
platform project and any placeholders updated as needed. Be sure that any changes
in app permissions, etc that you may make to the manifest are updated in the Template
as well. New secrets can be added to the template by adding `$$variableName$$` to
the template manifest. This will then be replaced automatically on the build server.

#### Build Server Setup
## Setting Up AppCenter

Any variables that may exist within the Manifest templates can be injected via a
token replacement. By default the Build Task will look for `$$` before and after
the variable name that you wish to replace. The build task will use any environment
variables that start with `Manifest_` to help facilitate token replacement.
You will need to setup your AppCenter build with whatever general settings you require. Then in the Environment Variables you will need to add a variable for each of the keys shown above for the `secrets.json`, note each will need to be prefixed with `Secret_`, so they become `Secret_AppCenter_iOS_Secret` and so on. Because we are also swapping out the Manifests we will need to add `Manifest_AppCenterSecret` for our iOS build so that it can replace the token. Once you've added these variables you are all set and ready to build. As you'll see in the image below while we do need to declare the Android Secret variable, we don't actually need to provide it a value since it's platform specific.

For example, you may add `Manifest_AADClientId` to the build environment, and have
`$$AADClientId$$` as a token within your manifest. The Mobile.BuildTools by default
will only copy Manifests when building a Platform target such as iOS, Android, UWP.
If the build definition builds more than one platform target, any variables that
should be different from one platform to the next should use platform specific
tokens within the manifest.
![AppCenter Environment Variables](images/AppCenter-Environment-Variables.png)
Binary file added images/AppCenter-Environment-Variables.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/AppCenter.DemoApp.Droid/Properties/AssemblyInfo.cs
Expand Up @@ -26,3 +26,8 @@
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

#if DEBUG
[assembly: Application(Debuggable = true)]
#else
[assembly: Application(Debuggable = false)]
#endif
5 changes: 3 additions & 2 deletions src/AppCenter.DemoApp/App.xaml.cs
Expand Up @@ -46,6 +46,7 @@ public App(IPlatformInitializer initializer)
// Handle when your app starts
Microsoft.AppCenter.AppCenter.Start(AppConstants.AppCenterStart,
typeof(Analytics), typeof(Crashes), typeof(Distribute), typeof(Push));
Container.Resolve<ILoggerFacade>().Log("Started AppCenter", Category.Info, Priority.Low);
}

protected override async void OnInitialized()
Expand Down Expand Up @@ -118,9 +119,9 @@ private ILoggerFacade CreateLogger()
return new DebugLogger();
}

private MCAnalyticsLogger CreateAppCenterLogger()
private ACAnalyticsLogger CreateAppCenterLogger()
{
var logger = new MCAnalyticsLogger();
var logger = new ACAnalyticsLogger();
FFImageLoading.ImageService.Instance.Config.Logger = (IMiniLogger)logger;
return logger;
}
Expand Down
Expand Up @@ -6,7 +6,7 @@

namespace AppCenter.DemoApp.Services
{
public class MCAnalyticsLogger : ILoggerFacade, IMiniLogger
public class ACAnalyticsLogger : ILoggerFacade, IMiniLogger
{
public void Debug(string message)
{
Expand Down
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<Reference Include="System" />
<PackageReference Include="NUnit" Version="2.6.*" />
<PackageReference Include="Xamarin.UITest" Version="2.*" />
<PackageReference Include="NUnit" Version="2.6.4" />
<PackageReference Include="Xamarin.UITest" Version="2.2.3" />
</ItemGroup>

</Project>

0 comments on commit d9f647f

Please sign in to comment.