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

Force to use id_token instead of access_token #405

Open
ddaddy opened this issue Jul 21, 2023 · 1 comment · May be fixed by #406
Open

Force to use id_token instead of access_token #405

ddaddy opened this issue Jul 21, 2023 · 1 comment · May be fixed by #406

Comments

@ddaddy
Copy link

ddaddy commented Jul 21, 2023

I need to provide the id_token to my API and not the access_token.

If I override the extensions that create the oauth2 signed request like this:

extension OAuth2Base {
    func request(forURL url: URL, cachePolicy: NSURLRequest.CachePolicy = .reloadIgnoringLocalCacheData) -> URLRequest {
        var req = URLRequest(url: url, cachePolicy: cachePolicy, timeoutInterval: 20)
        try? req.sign(with: self)
        return req
    }
}

extension URLRequest {
    public mutating func sign(with oauth2: OAuth2Base) throws {
        guard let idToken = oauth2.clientConfig.idToken, !idToken.isEmpty else {
            throw OAuth2Error.noAccessToken
        }
        setValue("Bearer \(idToken)", forHTTPHeaderField: "Authorization")
    }
}

This will work when making oauth2.session requests. However if I use OAuth2DataLoader it works while I have a valid token, but if the OAuth2DataLoader has to request a re-login and it gets a new token, the first request it fires off afterwards uses the access_token.

Is it possible to make it use the id_token instead?

@ddaddy ddaddy linked a pull request Jul 21, 2023 that will close this issue
@ddaddy
Copy link
Author

ddaddy commented Jul 21, 2023

I've created a pull request that adds this feature. #406

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

Successfully merging a pull request may close this issue.

1 participant