You can download this code by clicking the button below.
This code is now available for download.
This function randomly selects a provider from the list of providers the user is authenticated with.
Technology Stack : Authlib
Code Type : Function
Code Difficulty : Intermediate
def random_provider_list(user_id, providers):
"""
This function takes a user ID and a list of provider names, and returns a random provider
from the list that the user is authenticated with.
Args:
user_id (str): The ID of the user.
providers (list): A list of provider names the user is authenticated with.
Returns:
str: The name of the randomly selected provider.
"""
import random
from authlib.integrations.base import OAuth2Provider
selected_provider = random.choice(providers)
provider_class = OAuth2Provider(selected_provider)
return selected_provider