Пробовал это с кодом SDK:
Код: Выделить всё
def auth(request): options = getOptions() am = IdcsClient.AuthenticationManager(options) url = am.getAuthorizationCodeUrl(options["redirectURL"], options["scope"], "1234", "code") return HttpResponseRedirect(url)Код: Выделить всё
# Definition of the /callback route
def callback(request):
code = request.GET.get('code')
#Authentication Manager loaded with the configurations.
am = IdcsClient.AuthenticationManager(getOptions())
#Using the Authentication Manager to exchange the Authorization Code to an Access Token.
ar = am.authorizationCode(code)
#Get the access token as a variable
access_token = ar.getAccessToken()
#User Manager loaded with the configurations.
um = IdcsClient.UserManager(getOptions())
#Using the access_token value to get an object instance representing the User Profile.
u = um.getAuthenticatedUser(access_token)
#Getting the user details in json object format.
displayname = u.getDisplayName()
#The application then adds these information to the User Session.
request.session['access_token'] = access_token
request.session['displayname'] = displayname
#Rendering the home page and adding displayname to be printed in the page.
return render(request, 'sampleapp/home.html', {'displayname': displayname})
Я пробовал так
Код: Выделить всё
@app.get("/get_data")
def print_data():
auth()
# On success auth Proceed next
Проблема здесь в том, что даже если аутентификация не удалась, мы все равно продолжаем работу.
Могу ли я Есть пример кода, чтобы понять, как реализовать?
Подробнее здесь: https://stackoverflow.com/questions/792 ... on-fastapi
Мобильная версия