11# Configuration
22
3- ## Provider and client configuration
3+ Both static and dynamic provider configuration discovery, as well as static and dynamic client registration, is
4+ supported. The different modes of provider configuration can be combined with any of the client registration modes.
45
5- Both static and dynamic provider configuration discovery, as well as static
6- and dynamic client registration, is supported. The different modes of provider configuration can be combined with any
7- of the client registration modes.
6+ ## Client Configuration
87
9- ### Provider configuration
8+ ### Static Client Registration
109
11- #### Dynamic provider configuration
10+ If you have already registered a client with the provider, specify the client credentials directly:
11+ ``` python
12+ from flask_pyoidc.provider_configuration import ProviderConfiguration, ClientMetadata
13+
14+ client_metadata = ClientMetadata(client_id = ' client1' , client_secret = ' secret1' )
15+ ```
16+
17+ ** Note: The redirect URIs registered with the provider MUST include the URI specified in
18+ [ ` OIDC_REDIRECT_URI ` ] ( #flask-configuration ) .**
19+
20+
21+ ### Dynamic Client Registration
22+
23+ To dynamically register a new client for your application, the required client registration info can be specified:
24+
25+ ``` python
26+ from flask_pyoidc.provider_configuration import ProviderConfiguration, ClientRegistrationInfo
27+
28+ client_registration_info
= ClientRegistrationInfo(
client_name = ' Test App' ,
contacts = [
' [email protected] ' ])
29+ ```
30+
31+ ## Provider configuration
32+
33+ ### Dynamic provider configuration
1234
1335To use a provider which supports dynamic discovery it suffices to specify the issuer URL:
1436``` python
1537from flask_pyoidc.provider_configuration import ProviderConfiguration
1638
17- config = ProviderConfiguration(issuer = ' https://op.example.com' , [client configuration])
39+ # If you are using Static Client Configuration, then specify client_metadata
40+ # as shown above.
41+ provider_config = ProviderConfiguration(issuer = ' https://idp.example.com' ,
42+ client_metadata = client_metadata)
43+
44+ # If you are using Dynamic Client Registration, then specify
45+ # client_registration_info as shown above.
46+ provider_config = ProviderConfiguration(issuer = ' https://idp.example.com' ,
47+ client_registration_info = client_registration_info)
1848```
1949
20- #### Static provider configuration
50+ ### Static provider configuration
2151
2252To use a provider not supporting dynamic discovery, the static provider metadata can be specified:
2353``` python
2454from flask_pyoidc.provider_configuration import ProviderConfiguration, ProviderMetadata
2555
26- provider_metadata = ProviderMetadata(issuer = ' https://op.example.com' ,
27- authorization_endpoint = ' https://op.example.com/auth' ,
28- jwks_uri = ' https://op.example.com/jwks' ,
29- userinfo_endpoint = ' https://op.example.com/userinfo' )
30- config = ProviderConfiguration(provider_metadata = provider_metadata, [client configuration])
56+ provider_metadata = ProviderMetadata(issuer = ' https://idp.example.com' ,
57+ authorization_endpoint = ' https://idp.example.com/auth' ,
58+ token_endpoint = ' https://idp.example.com/token' ,
59+ introspection_endpoint = ' https://idp.example.com/introspect' ,
60+ userinfo_endpoint = ' https://idp.example.com/userinfo' ,
61+ end_session_endpoint = ' https://idp.example.com/logout' ,
62+ jwks_uri = ' https://idp.example.com/certs' ,
63+ registration_endpoint = ' https://idp.example.com/registration'
64+ )
65+ # As shown earlier, if you are using Static Client Configuration, then specify
66+ # client_metadata.
67+ provider_config = ProviderConfiguration(provider_metadata = provider_metadata,
68+ client_metadata = client_metadata)
69+
70+ # If you are using Dynamic Client Registration, then specify
71+ # client_registration_info.
72+ provider_config = ProviderConfiguration(provider_metadata = provider_metadata,
73+ client_registration_info = client_registration_info)
3174```
3275
3376See the OpenID Connect specification for more information about the
3477[ provider metadata] ( https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata ) .
3578
36- As mentioned in OpenID Connect specification, ` userinfo_endpoint ` is optional. If it's
37- not provided, no userinfo request will be done and ` flask_pyoidc.UserSession.userinfo ` will be set to ` None ` .
79+ As mentioned in OpenID Connect specification, ` userinfo_endpoint ` is optional. If it's not provided, no userinfo
80+ request will be done and ` flask_pyoidc.UserSession.userinfo ` will be set to ` None ` .
3881
39- #### Customizing authentication request parameters
82+ ### Customizing authentication request parameters
4083To customize the [ authentication request parameters] ( https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest ) ,
4184use ` auth_request_params ` in ` ProviderConfiguration ` :
4285``` python
4386auth_params = {' scope' : [' openid' , ' profile' ]} # specify the scope to request
44- config = ProviderConfiguration([provider/ client config], auth_request_params = auth_params)
87+ provider_config = ProviderConfiguration([provider/ client config], auth_request_params = auth_params)
4588```
4689
47- #### Session refresh
90+ ### Session refresh
4891
4992If your provider supports the ` prompt=none ` authentication request parameter, this extension can automatically refresh
5093user sessions. This ensures that the user attributes (OIDC claims, user being active, etc.) are kept up-to-date without
@@ -53,43 +96,36 @@ refreshes:
5396``` python
5497from flask_pyoidc.provider_configuration import ProviderConfiguration
5598
56- config = ProviderConfiguration(session_refresh_interval_seconds = 1800 , [provider/ client config])
99+ provier_config = ProviderConfiguration(session_refresh_interval_seconds = 1800 , [provider/ client config])
57100```
58101
59102** Note: The user will still be logged out when the session expires (as set in the Flask session configuration).**
60103
61- ### Client configuration
62-
63- #### Static client registration
104+ ## Client Credentials Flow
105+ The [ Client Credentials] ( https://tools.ietf.org/html/rfc6749#section-4.4 ) grant type is used by clients to obtain an access token outside of the context of a user.
64106
65- If you have already registered a client with the provider, specify the client credentials directly:
66- ``` python
67- from flask_pyoidc.provider_configuration import ProviderConfiguration, ClientMetadata
107+ This is typically used by clients to access resources about themselves rather than to access a user's resources.
68108
69- client_metadata = ClientMetadata(client_id = ' cl41ekfb9j' , client_secret = ' m1C659wLipXfUUR50jlZ' )
70- config = ProviderConfiguration([provider configuration], client_metadata = client_metadata)
71- ```
72-
73- ** Note: The redirect URIs registered with the provider MUST include the URI specified in
74- [ ` OIDC_REDIRECT_URI ` ] ( #flask-configuration ) .**
75-
76- #### Dynamic client registration
77-
78- To dynamically register a new client for your application, the required client registration info can be specified:
109+ Client can obtain access token by using ` client_credentials_grant ` .
79110
80111``` python
81- from flask_pyoidc.provider_configuration import ProviderConfiguration, ClientRegistrationInfo
112+ auth = OIDCAuthentication({ ' default ' : provider_config}, app)
82113
83- client_registration_info = ClientRegistrationInfo( client_name = ' Test App ' , contacts = [ ' [email protected] ' ] )
84- config = ProviderConfiguration([provider configuration], client_registration_info = client_registration_info )
114+ client_credentials_response = auth.clients[ ' default ' ].client_credentials_grant( )
115+ access_token = resp.get( ' access_token ' )
85116```
86117
118+ Use the obtained ` access_token ` to access your web service APIs.
119+ If your API endpoints are protected with ` @auth.token_auth ` or
120+ ` @auth.access_control ` , ` access_token ` will be verfied by token introspection
121+ before allowing access.
122+
87123## Flask configuration
88124
89125The application using this extension ** MUST** set the following configuration parameters:
90126
91- * ` SECRET_KEY ` : This extension relies on [ Flask sessions] ( http ://flask.pocoo.org/docs /quickstart/#sessions) , which
92- requires [ ` SECRET_KEY ` ] ( http ://flask.pocoo.org/docs /config/#builtin-configuration-values) .
127+ * ` SECRET_KEY ` : This extension relies on [ Flask sessions] ( https ://flask.palletsprojects.com/en/2.0.x /quickstart/#sessions) , which
128+ requires [ ` SECRET_KEY ` ] ( https ://flask.palletsprojects.com/en/2.0.x /config/#builtin-configuration-values) .
93129* ` OIDC_REDIRECT_URI ` : The URI used as redirect URI to receive authentication responses. This extension will add a url
94130 rule to handle all requests to the specified endpoint, so make sure the domain correctly points to your app and that
95131 the URL path is not already used in the app.
@@ -98,9 +134,9 @@ This extension also uses the following configuration parameters:
98134* ` OIDC_SESSION_PERMANENT ` : If set to ` True ` (which is the default) the user session will be kept until the configured
99135 session lifetime (see below). If set to ` False ` the session will be deleted when the user closes the browser.
100136* ` PERMANENT_SESSION_LIFETIME ` : Control how long a user session is valid, see
101- [ Flask documentation] ( http ://flask.pocoo.org/docs/1.0 /config/#PERMANENT_SESSION_LIFETIME) for more information.
137+ [ Flask documentation] ( https ://flask.palletsprojects.com/en/2.0.x /config/#PERMANENT_SESSION_LIFETIME) for more information.
102138
103- #### Legacy configuration parameters
139+ ### Legacy configuration parameters
104140The following parameters have been deprecated:
105141* ` OIDC_REDIRECT_DOMAIN ` : Set the domain (which may contain port number) used in the redirect_uri to receive
106142 authentication responses. Defaults to the ` SERVER_NAME ` configured for Flask.
0 commit comments