Move Blogger client ID and client secrets to JSON
Google asked us not to check in the client id and client secret into the source. Instead, we'll generate a client_secrets.json at runtime based on environment variables. Developers that want to build the source code locally will need to supply their own client ID and client secret. For the official Open Live Writer installer, we'll make sure the client ID and client secret are set to the official Open Live Writer client.
This commit is contained in:
parent
ad482780be
commit
3796993b2c
|
@ -1,6 +1,7 @@
|
|||
## Ignore automatically generated files.
|
||||
src/managed/GlobalAssemblyVersionInfo.cs
|
||||
src/unmanaged/version.h
|
||||
src/managed/OpenLiveWriter.BlogClient/Clients/GoogleBloggerv3Secrets.json
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
|
|
@ -21,6 +21,7 @@ using OpenLiveWriter.HtmlParser.Parser;
|
|||
using OpenLiveWriter.HtmlParser.Parser.FormAgent;
|
||||
using OpenLiveWriter.Localization;
|
||||
using Google.Apis.Blogger.v3;
|
||||
using System.Reflection;
|
||||
|
||||
namespace OpenLiveWriter.BlogClient.Clients
|
||||
{
|
||||
|
@ -29,6 +30,13 @@ namespace OpenLiveWriter.BlogClient.Clients
|
|||
{
|
||||
public static string PicasaServiceScope = "https://picasaweb.google.com/data";
|
||||
public static string BloggerServiceScope = BloggerService.Scope.Blogger;
|
||||
public static Stream ClientSecretsStream
|
||||
{
|
||||
get
|
||||
{
|
||||
return ResourceHelper.LoadAssemblyResourceStream("Clients.GoogleBloggerv3Secrets.json");
|
||||
}
|
||||
}
|
||||
|
||||
public BloggerAtomClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
|
||||
: base(AtomProtocolVersion.V10DraftBlogger, postApiUrl, credentials)
|
||||
|
|
|
@ -214,6 +214,17 @@
|
|||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(RepoRoot)\writer.build.targets" />
|
||||
<PropertyGroup>
|
||||
<BloggerClientSecretsJson>Clients\GoogleBloggerv3Secrets.json</BloggerClientSecretsJson>
|
||||
<OlwBloggerClientId Condition="'$(OlwBloggerClientId)'==''">ClientId</OlwBloggerClientId>
|
||||
<OlwBloggerClientSecret Condition="'$(OlwBloggerClientSecret)'==''">ClientSecret</OlwBloggerClientSecret>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Condition="Exists('$(BloggerClientSecretsJson)')" Include="$(BloggerClientSecretsJson)" />
|
||||
</ItemGroup>
|
||||
<Target Name="GenerateBloggerClientSecrets" DependsOnTargets="ResolveProjectReferences" BeforeTargets="CoreCompile" Outputs="$(BloggerClientSecretsJson)">
|
||||
<WriteLinesToFile File="$(BloggerClientSecretsJson)" Lines="{ "installed": { "client_id": "$(OlwBloggerClientId)", "client_secret": "$(OlwBloggerClientSecret)" } }" Overwrite="true" />
|
||||
</Target>
|
||||
<Target Name="BeforeBuild">
|
||||
<Copy SourceFiles="$(ProjectDir)Detection\default.htm" DestinationFiles="$(OutputPath)\template\default.htm" />
|
||||
<Copy SourceFiles="$(ProjectDir)Detection\defaultstyle.css" DestinationFiles="$(OutputPath)\template\defaultstyle.css" />
|
||||
|
|
|
@ -237,6 +237,18 @@ namespace OpenLiveWriter.CoreServices
|
|||
return icon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a raw stream from an assembly resource.
|
||||
/// </summary>
|
||||
/// <param name="resourcePath">Resource path.</param>
|
||||
/// <returns>Stream to the specified resource, or null if the resource could not be found.</returns>
|
||||
public static Stream LoadAssemblyResourceStream(string resourcePath)
|
||||
{
|
||||
Assembly assembly = Assembly.GetCallingAssembly();
|
||||
string resourceName = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", assembly.GetName().Name, resourcePath);
|
||||
return assembly.GetManifestResourceStream(resourceName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves an assembly resource to a file
|
||||
/// </summary>
|
||||
|
|
|
@ -54,11 +54,7 @@ namespace OpenLiveWriter.PostEditor.Configuration.Wizard
|
|||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
_userCredentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(
|
||||
new ClientSecrets()
|
||||
{
|
||||
ClientId = "clientId",
|
||||
ClientSecret = "clientSecret"
|
||||
},
|
||||
GoogleClientSecrets.Load(BloggerAtomClient.ClientSecretsStream).Secrets,
|
||||
new List<string>() { BloggerAtomClient.BloggerServiceScope, BloggerAtomClient.PicasaServiceScope },
|
||||
"user",
|
||||
_cancellationTokenSource.Token);
|
||||
|
|
Loading…
Reference in New Issue