Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To modify the OAuth flow in httr2 to utilize idtoken instead of accesstoken, you need to make the following changes:

  1. Update the authorization endpoint to include the OpenID Connect scope (openid). This scope is required to request an id_token.

  2. Set the response_type parameter in the authorization request to code id_token.

  3. Request the id_token parameter in the token request.

  4. Verify the id_token received from the token endpoint to ensure its authenticity.

Here is an example code snippet:

```{r} library(httr)

Define OAuth endpoints

authurl <- "https://example.com/oauth2/authorize" tokenurl <- "https://example.com/oauth2/token" clientid <- "yourclientid" clientsecret <- "yourclientsecret" redirect_uri <- "https://localhost:1410"

Create OAuth client

myapp <- oauthapp("myapp", key = clientid, secret = clientsecret, redirecturi = redirect_uri)

Define authorization parameters

authparams <- list(scope = "openid", responsetype = "code idtoken", redirecturi = redirect_uri, state = "myapp")

Generate authorization URL

authurl <- oauth2.0authorizeurl(myapp, authurl, auth_params)

Open web browser and get authorization code and id_token from the redirect URI

Define token parameters

tokenparams <- list(granttype = "authorizationcode", redirecturi = redirecturi, code = "yourauthorizationcodereceivedfromtheredirecturi", id_token = "true")

Request access token and id_token

token <- oauth2.0token(tokenurl, myapp, token_params)

Verify authenticity of id_token

jwt::jwtdecode(token$idtoken)

Use id_token for further API requests

```