Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetTokenAsync throws exception without redirectUri #237

Open
JohanForngren opened this issue Mar 7, 2022 · 4 comments
Open

GetTokenAsync throws exception without redirectUri #237

JohanForngren opened this issue Mar 7, 2022 · 4 comments

Comments

@JohanForngren
Copy link

When I try to get auth codes using the API version 4.3.1 without passing a redirectUri or setting it to null I get the exception:
{"Message":"An error has occurred.","ExceptionMessage":"Request failed: The redirect URI is missing or do not match",

using Fortnox.SDK;
using Fortnox.SDK.Auth;

// Constructor
private readonly FortnoxAuthClient _fortnoxAuthClient = new FortnoxAuthClient();
private readonly IStandardAuthWorkflow _authWorkflow  = _fortnoxAuthClient.StandardAuthWorkflow;

// This works fine without redirectUri, and is accepted by fortnox, redirecting back
Scope[] scopes = {Scope.CompanyInformation};
var authUri = _authWorkflow.BuildAuthUri(_clientId, scopes, state);

// Throws the above exception.
var tokenInfo = await _authWorkflow.GetTokenAsync(authorizationCode, _clientId, _clientSecret);

// Throws the above exception.
var tokenInfo = await _authWorkflow.GetTokenAsync(authorizationCode, _clientId, _clientSecret, null);

// This works.
string _redirectUri = "https://same-url-as-configured-at-fortnox-dev-portal";
var tokenInfo = await _authWorkflow.GetTokenAsync(authorizationCode, _clientId, _clientSecret, _redirectUri);

I've tried it on both in dev environment and at the _redirectUri host with the same results. I haven't yet tried it with other parts of the API.

@richardrandak
Copy link
Collaborator

The error message is from the API, so it seems the redirect URI is required for obtaining the token.
All I can do is to make the argument mandatory also in the method signature, instead of null-by-default to force users to specify it.

@JohanForngren
Copy link
Author

@richardrandak It should be optional according to the docs:
https://developer.fortnox.se/general/authentication/

I will email Fortnox support, referencing this issue.

@strndi
Copy link

strndi commented Mar 7, 2022

It's not really optional, It's only optional for test apps, if you want to to list your app on their app market - you have to use a redirect URI else your app won't be published.

@JohanForngren
Copy link
Author

Reply from Fortnox below. Does not match my experience, but I haven't confirmed using the rest api directly.

8 mars 2022 08:31 CET
Hej!

Det är optional att ta med den i authorization URL:en. Tar du inte med den så kommer den automatiskt att hämtas från er utvecklarportal.

Önskar er en trevlig dag!
Med vänliga hälsningar
Fortnox AB

Besökare
7 mars 2022 17:33 CET
Hej,
Okej, men är redirect_uri optional för Get Authorization-Code såsom det står här? Eller behöver jag faktiskt skicka med den ändå?
Authorization | Fortnox Developer (https://developer.fortnox.se/general/authentication/)
Tack!
Johan

7 mars 2022 15:51 CET
Hej Johan!

När det kommer till vårt SDK är detta numera Opensource och inget som vi på Fortnox supporterar.

Detta sköts helt via GitHub.

Tack,
Med vänliga hälsningar
Fortnox AB
http://www.fortnox.se

Besökare
7 mars 2022 12:53 CET
Hej!
Använder csharp-apiet och får felmeddelanden som tycks avvika från förväntat beteende enligt dokumentationen. Se GetTokenAsync throws exception without redirectUri · Issue #237 · FortnoxAB/csharp-api-sdk (github.com) för detaljer.
Tack!
Johan Forngren

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants