Skip to content

Commit

Permalink
- Moved YammerServiceUrl and AppClientId into YamsterApiSettings, eli…
Browse files Browse the repository at this point in the history
…minating YamsterApiConfig

- Yamster can now login to networks using non-SSO authentication
- The login form now clears cookies to avoid some login errors
- Now using a newer OAuth2 algorithm that doesn't require the app's client secret
  • Loading branch information
pgonzal committed Apr 29, 2015
1 parent 9fc7071 commit f502dd4
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 353 deletions.
11 changes: 3 additions & 8 deletions Source/Yamster.Core/Model/AppContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,18 @@ public class AppContext : IDisposable

AsyncRestCaller asyncRestCaller;
YamsterApi yamsterApi;
YamsterApiConfiguration configuration;
MessagePuller messagePuller;
LightweightUserManager userManager;
ImageCache imageCache;

static AppContext defaultInstance = null;

public AppContext(YamsterApiConfiguration configuration)
public AppContext()
{
this.ValidateOsEnvironment();

this.foregroundThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;

this.configuration = configuration;

this.settings = new YamsterApiSettings(this);
this.settings.Load();
this.settings.Save(); // normalize settings file
Expand Down Expand Up @@ -145,10 +142,9 @@ public static void InitializeDefaultInstance(AppContext defaultInstance)
AppContext.defaultInstance = defaultInstance;
}

public static void InitializeDefaultInstance(string consumerKey, string consumerSecret)
public static void InitializeDefaultInstance()
{
var config = new YamsterApiConfiguration(consumerKey, consumerSecret);
InitializeDefaultInstance(new AppContext(config));
InitializeDefaultInstance(new AppContext());
}

public static void UninitializeDefaultInstance()
Expand All @@ -170,7 +166,6 @@ public static AppContext Default {
}
}

public YamsterApiConfiguration Configuration { get { return this.configuration; } }
public YamsterApiSettings Settings { get { return this.settings; } }

public AsyncRestCaller AsyncRestCaller { get { return this.asyncRestCaller; } }
Expand Down
59 changes: 0 additions & 59 deletions Source/Yamster.Core/Model/YamsterApiConfig.cs

This file was deleted.

55 changes: 52 additions & 3 deletions Source/Yamster.Core/Model/YamsterApiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class YamsterApiSettings
const string UnprotectedPrefix = "(Unprotected)";

AppContext appContext;
string yammerServiceUrl;
string appClientId;
string oAuthToken;
bool protectTokenWhenSaving;

Expand All @@ -53,6 +55,34 @@ public YamsterApiSettings(AppContext appContext)

#region Properties

public string YammerServiceUrl
{
get { return this.yammerServiceUrl; }
set {
if (value == null)
throw new ArgumentNullException("AppClientId");
Uri parsed = new Uri(value);
if (parsed.Scheme != "http" && parsed.Scheme != "https")
throw new ArgumentException("Invalid YammerServiceUrl");

this.yammerServiceUrl = value.TrimEnd('/');
}
}

/// <summary>
/// The Yammer ClientId that the application uses for authentication.
/// </summary>
public string AppClientId
{
get { return this.appClientId; }
set
{
if (value == null)
throw new ArgumentNullException("AppClientId");
this.appClientId = value;
}
}

/// <summary>
/// The session token for accessing the Yammer REST service.
/// </summary>
Expand Down Expand Up @@ -90,6 +120,8 @@ string GetSettingsFilePath()

public void ResetDefaults()
{
yammerServiceUrl = "https://www.yammer.com";
appClientId = "";
oAuthToken = "";
protectTokenWhenSaving = true;
}
Expand All @@ -115,7 +147,11 @@ private void Load(string filename)
{
XDocument document = XDocument.Load(streamReader, LoadOptions.SetLineInfo);

ReadAuthenticationProperties(document.Root);
var rootElement = document.Root;

Version version = new Version(XmlUtilities.GetStringAttribute(rootElement, "Version"));

ReadAuthenticationProperties(rootElement, version);
}
succeeded = true;
}
Expand All @@ -126,10 +162,19 @@ private void Load(string filename)
}
}

private void ReadAuthenticationProperties(XElement rootElement)
private void ReadAuthenticationProperties(XElement rootElement, Version version)
{
var authenticationElement = XmlUtilities.GetChildElement(rootElement, "Authentication");

if (version >= new Version(1,1))
{
var yammerServiceUrlElement = XmlUtilities.GetChildElement(rootElement, "YammerServiceUrl");
this.YammerServiceUrl = yammerServiceUrlElement.Value;

var appClientIdElement = XmlUtilities.GetChildElement(authenticationElement, "AppClientId");
this.AppClientId = appClientIdElement.Value;
}

var oAuthTokenElement = XmlUtilities.GetChildElement(authenticationElement, "OAuthToken");
string unprocessedToken = oAuthTokenElement.Value ?? "";

Expand Down Expand Up @@ -173,7 +218,7 @@ private void Save(string filename)
rootElement
);

rootElement.Add(new XAttribute("Version", "1.0"));
rootElement.Add(new XAttribute("Version", "1.1"));
WriteAuthenticationProperties(rootElement);

var xmlWriterSettings = new XmlWriterSettings() { Indent = true, IndentChars = " " };
Expand All @@ -188,7 +233,11 @@ private void Save(string filename)
private void WriteAuthenticationProperties(XElement rootElement)
{
var authenticationElement = new XElement("Authentication");

rootElement.Add(new XElement("YammerServiceUrl", this.YammerServiceUrl));

rootElement.Add(authenticationElement);
authenticationElement.Add(new XElement("AppClientId", this.AppClientId));

string processedToken;
if (string.IsNullOrWhiteSpace(this.OAuthToken))
Expand Down
2 changes: 1 addition & 1 deletion Source/Yamster.Core/Protocol/AsyncRestCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private string buildAbsoluteUrl(string url)
return url;
}

return this.appContext.Configuration.WebApiUrl + url;
return this.appContext.Settings.YammerServiceUrl + url;
}

private string getFinalUrl(string method, Dictionary<string, string> parameters, string part)
Expand Down
1 change: 0 additions & 1 deletion Source/Yamster.Core/Yamster.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
<Compile Include="Model\YamsterModelEventCollector.cs" />
<Compile Include="Model\YamsterNewMessage.cs" />
<Compile Include="Model\YamsterApiSettings.cs" />
<Compile Include="Model\YamsterApiConfig.cs" />
<Compile Include="Model\YamsterThread.cs" />
<Compile Include="Model\YamsterUser.cs" />
<Compile Include="Model\YamsterUserSet.cs" />
Expand Down
10 changes: 3 additions & 7 deletions Source/Yamster.Native-Mac/Logon/YammerLogonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@ namespace Yamster.Native
{
public class YammerLogonManager
{
public string ConsumerKey { get; private set; }
public string ConsumerSecret { get; private set; }
public string YammerServiceUrl { get; private set; }
public string AppClientId { get; private set; }

public string UserName { get; set; }
public string AccessToken { get; set; }

public YammerLogonManager(string consumerKey, string consumerSecret, string yammerServiceUrl)
public YammerLogonManager(string yammerServiceUrl, string appClientId)
{
this.ConsumerKey = consumerKey;
this.ConsumerSecret = consumerSecret;
this.YammerServiceUrl = yammerServiceUrl;
this.AppClientId = appClientId;

UserName = "";
AccessToken = "";
}

Expand Down
108 changes: 0 additions & 108 deletions Source/Yamster.Native-Win32/Logon/SsoUrlParser.cs

This file was deleted.

Loading

0 comments on commit f502dd4

Please sign in to comment.