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

[.NET SDK] ApiToken Credentials not working #58

Closed
Mattieeec3 opened this issue Nov 15, 2022 · 3 comments · Fixed by #63
Closed

[.NET SDK] ApiToken Credentials not working #58

Mattieeec3 opened this issue Nov 15, 2022 · 3 comments · Fixed by #63
Assignees
Labels
bug Something isn't working dotnet-sdk Affects the C#/DotNet SDK good first issue Good for newcomers

Comments

@Mattieeec3
Copy link

The ApiToken authentication method does not seem to be working, no authorization header is passed even though it is configured.
I took a glance at the code and the BaseClient seems to be created before the Authorization headers get added to the configuration's DefaultHeaders.

ApiClient.cs

public ApiClient(Configuration.Configuration configuration, HttpClient? userHttpClient = null) {
        configuration.IsValid();
        _configuration = configuration;
        _baseClient = new BaseClient(configuration, userHttpClient);

        if (configuration.Credentials == null) {
            return;
        }

        switch (configuration.Credentials.Method) {
            case CredentialsMethod.ApiToken:
                configuration.DefaultHeaders.Add("Authorization", $"Bearer {configuration.Credentials.Config!.ApiToken}");
                break;
            case CredentialsMethod.ClientCredentials:
                _oauth2Client = new OAuth2Client(configuration.Credentials, _baseClient);
                break;
            case CredentialsMethod.None:
            default:
                break;
        }
    }
@rhamzeh rhamzeh added bug Something isn't working dotnet-sdk Affects the C#/DotNet SDK labels Nov 15, 2022
@rhamzeh
Copy link
Member

rhamzeh commented Nov 15, 2022

Thanks for raising this @Mattieeec3!

It seems we're missing a test case for this, we'll add then and push out a new release shortly.

(Note: replaces openfga/dotnet-sdk#8)

@rhamzeh rhamzeh self-assigned this Nov 15, 2022
@rhamzeh rhamzeh added the good first issue Good for newcomers label Nov 15, 2022
rhamzeh added a commit that referenced this issue Nov 15, 2022
…sed (#63)

* fix(dotnet-sdk): resolve authorization token not send when ApiToken used

fixes #58
rhamzeh added a commit that referenced this issue Nov 15, 2022
changes:
- feat: regenerate from latest API Document, changes include:
    - documentation fixes
    - types that represent enabling wildcards in authorization models
- fix: send authorization header to server when ApiToken used (#58)
- chore: update test dependencies
rhamzeh added a commit that referenced this issue Nov 15, 2022
changes:
- feat: regenerate from latest API Document, changes include:
    - documentation fixes
    - types that represent enabling wildcards in authorization models
- fix: send authorization header to server when ApiToken used (#58)
- chore: update test dependencies
rhamzeh added a commit to openfga/dotnet-sdk that referenced this issue Nov 15, 2022
- feat: regenerate from latest API Document, changes include:
    - documentation fixes
    - types that represent enabling wildcards in authorization models
- fix: send authorization header to server when ApiToken used (openfga/sdk-generator#58)
- chore: update test dependencies
@rhamzeh
Copy link
Member

rhamzeh commented Nov 16, 2022

v0.1.2 should be out resolving this issue.

Thanks for reporting this and tracking down the fix @Mattieeec3!

@Mattieeec3
Copy link
Author

Mattieeec3 commented Nov 16, 2022

I can confirm it works now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dotnet-sdk Affects the C#/DotNet SDK good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants