How to get access to the URL segments after a # in Python Flask?

前端 未结 2 2144
暖寄归人
暖寄归人 2020-12-12 01:31

I\'m trying to support OAuth2 login through Python Flask, so I want to handle a URL that looks like this:

    http://myserver/loggedIn#accessToken=thisIsReal         


        
2条回答
  •  鱼传尺愫
    2020-12-12 01:58

    You are using the incorrect OAuth 2 grant type (implicit grant) for what you want to do. Implicit grant supplies the token in the fragment as you observed to be used by a javascript client. There is another type of grant, authorization code, which is similar but supplies it in the URI query which you can access from Flask.

    You can tell the two apart from the the redirect URI you create for authorization, if it has response_code=code you are on the right track. You currently use response_code=token.

    If you are using Facebook look at https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/

    For Google look at https://developers.google.com/accounts/docs/OAuth2WebServer

    You might also be interested in https://flask-oauthlib.readthedocs.org/en/latest/ which can help you with OAuth.

提交回复
热议问题