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

Code Challenge Method Type Error #1533

Closed
Rmutek opened this issue Apr 3, 2023 · 1 comment
Closed

Code Challenge Method Type Error #1533

Rmutek opened this issue Apr 3, 2023 · 1 comment
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@Rmutek
Copy link

Rmutek commented Apr 3, 2023

Hi there,

When attempting to set code_challenge_method: 'S256', I am getting the following error "Type '"S256"' is not assignable to type 'CodeChallengeMethod | undefined'.ts(2322)"

'S256' is an accepted value according to CodeChallengeMethod but when I pass that string in I get a type error

Seems like something is off with the type that is expected to be passed in. If I do this, code_challenge_method: <any>'S256', it works fine.

This is how I have this block set-up.

  const authorizeUrl = oAuth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: 'https://www.googleapis.com/auth/gmail.compose https://www.googleapis.com/auth/gmail.send https://www.googleapis.com/auth/gmail.modify https://mail.google.com/',
    code_challenge_method: 'S256',
    code_challenge: codes.codeChallenge,
  });

Environment details

  • OS: macOS Monterey 12.6
  • Node.js version: 16.16
  • yarn version: v1.22.18
  • google-auth-library version: 8.7.0

Steps to reproduce

  1. Using typescript attempt to set code_challenge_method to 'S256' and get a type error

Thanks!

@Rmutek Rmutek added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Apr 3, 2023
@sofisl
Copy link
Contributor

sofisl commented May 23, 2023

Hi @Rmutek! This field is an enum, so you'll have to do the following in your code:

import {CodeChallengeMethod, OAuth2Client} from 'google-auth-library';

then in the generateAuthUrl method, you'll write:

code_challenge_method: CodeChallengeMethod.S256,

And that should work. Feel free to reopen if this doesn't work for you!

@sofisl sofisl closed this as completed May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants