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

GraphAPI GetAccessTokenFromRefreshToken missing parameter #18

Closed
kennyvv opened this issue Mar 6, 2019 · 3 comments
Closed

GraphAPI GetAccessTokenFromRefreshToken missing parameter #18

kennyvv opened this issue Mar 6, 2019 · 3 comments
Assignees
Labels

Comments

@kennyvv
Copy link

kennyvv commented Mar 6, 2019

I was trying to use the GraphAPI and AuthenticateUsingRefreshToken, however i get the following exception.

KoenZomers.OneDrive.Api.Exceptions.TokenRetrievalFailedException: Failed to retrieve OneDrive access token. Additional information: AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'. Trace ID: ae843ab5-b298-4ff5-bd4e-7f52660a2300 Correlation ID: 8ce4b213-b349-47b2-8fc6-a21928a18c8b Timestamp: 2019-03-06 12:58:00Z at KoenZomers.OneDrive.Api.OneDriveApi.PostToTokenEndPoint(QueryStringBuilder queryBuilder) at KoenZomers.OneDrive.Api.OneDriveGraphApi.GetAccessTokenFromRefreshToken(String refreshToken, String[] scopes) at KoenZomers.OneDrive.Api.OneDriveGraphApi.GetAccessTokenFromRefreshToken(String refreshToken) at KoenZomers.OneDrive.Api.OneDriveApi.AuthenticateUsingRefreshToken(String refreshToken) --- End of inner exception stack trace ---

I thought i might have to set the client secret, however i can't set the property.
What is the issue here?

@KoenZomers
Copy link
Owner

Sorry for the late follow up on this one. Can you try this again using the latest version? I remember fixing something which could be related to this around the time you reported it. If the issue still exists and you're still in need for a solution, it would help if you can share a Fiddler capture of the request being made via e-mail with me. Don't upload it here.

@kgamecarter
Copy link
Contributor

kgamecarter commented Oct 4, 2019

When I use custom redirect url.
Must provide client_secret in GetAccessTokenFromAuthorizationToken and GetAccessTokenFromRefreshToken.

public class MyOneDriveGraphApi : OneDriveGraphApi
{
    public MyOneDriveGraphApi(string applicationId, string clientSecret) : base(applicationId, clientSecret)
    {
        OneDriveApiBaseUrl = GraphApiBaseUrl + "me/";
    }

    protected override async Task<OneDriveAccessToken> GetAccessTokenFromAuthorizationToken(string authorizationToken)
    {
        var queryBuilder = new QueryStringBuilder();
        queryBuilder.Add("client_id", ClientId);
        queryBuilder.Add("scope", DefaultScopes.Aggregate((x, y) => $"{x} {y}"));
        queryBuilder.Add("code", authorizationToken);
        queryBuilder.Add("redirect_uri", AuthenticationRedirectUrl);
        queryBuilder.Add("grant_type", "authorization_code");
        queryBuilder.Add("client_secret", ClientSecret); // Add this
        return await PostToTokenEndPoint(queryBuilder);
    }

    protected override async Task<OneDriveAccessToken> GetAccessTokenFromRefreshToken(string refreshToken)
    {
        var queryBuilder = new QueryStringBuilder();
        queryBuilder.Add("client_id", ClientId);
        queryBuilder.Add("scope", DefaultScopes.Aggregate((x, y) => $"{x} {y}"));
        queryBuilder.Add("refresh_token", refreshToken);
        queryBuilder.Add("redirect_uri", AuthenticationRedirectUrl);
        queryBuilder.Add("grant_type", "refresh_token");
        queryBuilder.Add("client_secret", ClientSecret);
        return await PostToTokenEndPoint(queryBuilder);
    }
}

@KoenZomers
Copy link
Owner

Merged your PR to resolve this.

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

No branches or pull requests

3 participants