FamilySearch / gedcomx-csharp

C# Libraries for GEDCOM X Processing
Apache License 2.0
42 stars 21 forks source link

State transitions fail when domain of target resource is different than the domain of the source resource #30

Closed stoicflame closed 9 years ago

stoicflame commented 9 years ago

If a resource links to a resource at a different domain, the request attempt will be made to the domain of the source resource.

For example, when an attempt to authenticate in production to an instance of FamilySearchFamilyTree, the Family Tree state is at "https://familysearch.org/platform/collections/tree" and the link to the OAuth 2 authentication resource is at "https://ident.familysearch.org/cis-web/oauth2/v3/token", but the AuthenticateViaOAuth2 method attempts to authenticate to "https://familysearch.org/cis-web/oauth2/v3/token" and not "ident.familysearch.org".

@shanewalters, I would appreciate any advice you can provide to fix this issue.

owentlarkin commented 9 years ago

The authenticateviaoauth2 works in the sandbox. The request goes to https://sandbox.familysearch.org/cis-web/oauth2/v3/token. The request in production goes to https://familysearch.org/cis-web/oauth2/v3/token and gets 404 . My guess would be there is a link in the sandbox that doesn't exist in production. I was able to create a hack to make it work in production for now.

I saved out the baser of the embedded client in the familysearch object.

string rc = Program.ft.Client.BaseUrl;

if the connection is for production I set the baseurl to the base of the token link if (!Program.useSandbox) { Uri urx = new System.Uri(Program.ft.GetLink(Rel.OAUTH2_TOKEN).Href);

 Program.ft.Client.BaseUrl = urx.GetBaseUrl();
}

after the authentication call, I restore the baseurl if it is production.

if (!Program.useSandbox)
{
 Program.ft.Client.BaseUrl = rc;
}
ghost commented 9 years ago

See pull request https://github.com/FamilySearch/gedcomx-csharp/pull/31. This is my proposed solution.

stoicflame commented 9 years ago

Merged #31.