def METHOD_NAME(self, payload, user, **kwargs):
    error = ApiError.RESOURCE_INVALID.copy()
    provider = payload.get('provider')
    token = payload.get('token')
    if not provider or provider not in VALID_OAUTH_PROVIDERS:
        error.update(dict(message='Invalid provider.'))
        raise ApiError(error)
    if not token:
        error.update(dict(message='Invalid token.'))
        raise ApiError(error)
    client_id = self.get_client_id(provider)
    oauth_client = Oauth2Application.query.filter(
        Oauth2Application.client_id == client_id,
    ).first()
    if not oauth_client:
        oauth_client = Oauth2Application.METHOD_NAME(
            client_id=client_id,
            client_type=Oauth2Application.ClientType.PRIVATE,
            name=provider,
            user_id=user.id if user else None,
        )
    access_token = Oauth2AccessToken.query.filter(
        Oauth2AccessToken.token == token,
    ).first()
    if access_token:
        access_token.expires = datetime.utcnow() + timedelta(days=30)
        access_token.save()
    else:
        access_token = generate_access_token(
            user,
            application=oauth_client,
            duration=int(timedelta(days=30).total_seconds()),
            token=token,
        )
    return self(
        dict(
            authenticated=True,
            expires=access_token.expires,
            provider=provider,
        ),
        user,
        **kwargs,
    )