Get social sign-in provider tokens
You can get the OIDC / OAuth 2.0 access, refresh, and ID tokens issued for the identity by social sign-in providers.
By default, Ory stores the tokens in the initial_access_token, initial_refresh_token, and initial_id_token fields, and only
when the Identity:
- Signs up with a social sign-in provider.
- Links a new social sign-in provider to their account.
Ory never overwrites the initial_* fields. To also store the tokens of later sign-ins, see
Get the tokens of the latest sign-in.
Run this command to get the Identity details that include the social sign-in provider tokens:
- Ory CLI
- cURL
- JavaScript
- Go
ory get identity "$identity_id" --project "$PROJECT_ID" \
-i oidc --format yaml
curl --request GET -sL \
--header "Content-Type: application/json" \
--header "Authorization: Bearer {ORY_API_KEY}" \
'https://$PROJECT_SLUG.projects.oryapis.com/admin/identities/<identity_id>?include_credential=oidc'
// Copyright © 2026 Ory Corp
import { Configuration, IdentityApi } from "@ory/client"
const identity = new IdentityApi(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function getTokens(identityId: string) {
return await identity
.getIdentity({ id: identityId, includeCredential: ["oidc"] })
.then(({ data }) => data)
}
// Copyright © 2026 Ory Corp
package main
import (
"context"
"fmt"
"github.com/ory/client-go"
"os"
)
var ory *client.APIClient
var authed = context.WithValue(context.Background(), client.ContextAccessToken, os.Getenv("ORY_API_KEY"))
func init() {
cfg := client.NewConfiguration()
cfg.Servers = client.ServerConfigurations{
{URL: fmt.Sprintf("https://%s.projects.oryapis.com", os.Getenv("ORY_PROJECT_SLUG"))},
}
ory = client.NewAPIClient(cfg)
}
func getTokens(identityId string) (cl client.IdentityCredentials, err error) {
identity, _, err := ory.IdentityAPI.
GetIdentity(authed, identityId).
IncludeCredential([]string{"oidc"}).Execute()
if err != nil {
return cl, err
}
return (*identity.Credentials)["oidc"], nil
}
When the call is successful, the system returns the Identity details with the available social sign-in provider tokens:
{
"id": "IDENTITY_ID",
"credentials": {
"oidc": {
"type": "oidc",
"identifiers": [
"google:some-user"
"github:another-user"
],
"config": {
"providers": [
{
"subject": "some-user",
"provider": "google",
"initial_access_token": "********************",
"initial_refresh_token": "********************",
"initial_id_token": "********************",
},
{
"subject": "another-user",
"provider": "github",
"initial_access_token": "********************",
"initial_refresh_token": "********************",
"initial_id_token": "********************",
}
]
},
"created_at": "2022-10-08T12:17:18.834351+02:00",
"updated_at": "2022-10-08T12:17:18.834351+02:00"
}
},
"schema_id": "default",
"schema_url": "SCHEMA_URL",
"state": "active",
"state_changed_at": "2022-10-08T12:17:18.83324+02:00",
"traits": {
"subject": "[email protected]"
},
"verifiable_addresses": [
{
"id": "88da96df-0457-4d69-832d-5e70ef25055c",
"value": "[email protected]",
"verified": false,
"via": "",
"status": "",
"verified_at": null,
"created_at": "2022-10-08T12:17:18.83324+02:00",
"updated_at": "2022-10-08T12:17:18.834202+02:00"
}
],
"created_at": "2022-10-08T12:17:18.834043+02:00",
"updated_at": "2022-10-08T12:17:18.834043+02:00"
}
Get the tokens of the latest sign-in
Set update_tokens_on_login to automatic on the provider to store the tokens issued at every sign-in. Ory saves them in the
access_token, id_token, and access_token_expires_at fields of the provider entry. The initial_* fields stay unchanged. The
default value is never.
Ory also fills the new fields at sign-up and when an Identity links the provider, if the setting is automatic at that time. For
providers linked while the setting was never, Ory fills the fields at the next sign-in after you turn the setting on.
Configure in the Ory Console
- Go to Authentication → Social Sign-In (OIDC) in the Ory Console.
- Select the provider you want to configure.
- Open advanced settings.
- Set Update tokens on login to automatic.
Configure via the CLI
ory patch identity-config --project <project-id> \
--replace '/selfservice/methods/oidc/config/providers/0/update_tokens_on_login="automatic"'
Or set it in the full provider configuration:
{
"selfservice": {
"methods": {
"oidc": {
"config": {
"providers": [
{
"id": "google",
"provider": "google",
"update_tokens_on_login": "automatic"
}
]
}
}
}
}
}
Read the tokens
Use the same request as above. A provider entry now has both sets of fields:
{
subject: "some-user",
provider: "google",
initial_access_token: "********************",
initial_refresh_token: "********************",
initial_id_token: "********************",
access_token: "********************",
id_token: "********************",
access_token_expires_at: "2022-10-09T12:17:18.834351+02:00",
}
Rules
With update_tokens_on_login set to automatic:
- Ory replaces the access token, the ID token, and the expiry at every sign-in.
access_token_expires_atis the time the access token expires. Ory stores it unencrypted.- Ory doesn't return the refresh token of the latest sign-in.
initial_refresh_tokenkeeps the refresh token from the time the Identity linked the provider. - If the token response has no ID token or no expiry, Ory clears that stored value.
- Ory updates only the provider used for the sign-in.
- Sign-ins where a native app submits an ID token directly store nothing. OAuth1 providers store nothing either.
- The setting adds one additional database write to every sign-in with that provider.
- Each sign-in that stores tokens emits an identity-updated event.
- If Ory can't store the tokens, the sign-in still succeeds and the stored tokens stay as they were.
- The session (
whoami) API never returns the tokens, and Ory never sends them in webhooks.
Encryption
The Ory Network encrypts the initial_* tokens and the tokens stored on login per default at rest using
XChaCha20 Poly1305.