E-Payment Integrator 2020 Python Edition

Questions / Feedback?

client_profile Property

The type of client that is requesting authorization.

Syntax

def get_client_profile() -> int: ...
def set_client_profile(value: int) -> None: ...

client_profile = property(get_client_profile, set_client_profile)

Default Value

0

Remarks

This defines the type of client that will be requesting authorization. Set this before calling get_authorization to inform the class to act accordingly. Possible values are:

0 (cfApplication - default)User application such as a windows form application
1 (cfWebServer) Server side application such as a website
2 (cfDevice) Device application without a browser such as a game console
3 (cfMobile) Mobile application with browser support such as a smart phone or tablet
4 (cfBrowser) Client side browser application such as JavaScript
5 (cfJWT) Server to Server authentication using a JWT Bearer Token

Application Client Type

The application client type is applicable to applications that are run by the user directly. For instance a windows form application would use the application client type. To authorize your application (client) using the application client type follow the steps below.

First, set client_profile to cfApplication. This defines the client type the class will use. Set the client_id, client_secret, server_auth_url, and server_token_url to the values you obtained when registering your application.

Next, call get_authorization to begin the authorization process. When get_authorization is called the class will build the URL to which the user will be directed and fire the on_launch_browser event. The class will then launch the browser using the command and URL shown in the on_launch_browser event.

The user will authenticate to the service, and then be redirected back to an embedded web server that was automatically started when get_authorization was called. At this time the on_return_url event will fire. This event provides an opportunity to provide a custom response to your user that they will see in their browser.

The class will then automatically exchange the grant that was returned by the authorization server for the access token using the HTTP endpoint specified in server_token_url.

The authorization is now complete and the get_authorization method will return the authorization string. To use the authorization string with any of our classs simply pass this value to the Authorization property before making the request.

A simple example is shown below.

component.ClientId = "MyId";
component.ClientSecret = "MyPassword";
component.ServerAuthURL = "https://accounts.google.com/o/oauth2/auth";
component.ServerTokenURL = "https://accounts.google.com/o/oauth2/token";
HTTP.Authorization = component.GetAuthorization();
HTTP.Get("https://www.googleapis.com/oauth2/v1/userinfo");

WebServer Client Type

The WebServer client type is applicable to applications that are run on the server side where the user uses the application from a web browser. To authorize your application (client) using this client type follow the steps below.

First, set client_profile to cfWebServer. This defines the client type the component will use. Set the client_id, client_secret, server_auth_url, and server_token_url to the values you obtained when registering your application. Set return_url to the page on your site that will be the endpoint the user is redirected back to after authentication.

Next, call get_authorization_url. This will return a URL to which the user should be redirected. Redirect the user to this URL.

After the user authenticates and is returned to the page on your site specified by return_url, parse the "code" query string parameter from the incoming request. Set authorization_code to this value.

Call get_authorization to exchange the code specified in authorization_code for a token from the server specified by server_token_url. get_authorization returns the authorization string. To use the authorization string with any of our components simply pass this value to the Authorization property before making the request.

Device Client Type

The Device client type is applicable to applications that are run on devices where no web browser can be used. For instance a game console would use the device client type. To authorize your application (client) using the device client type follow the steps below.

First, set client_profile to cfDevice. This defines the client type the class will use. Set the client_id, client_secret, server_auth_url, and server_token_url to the values you obtained when registering your application. Do not set return_url.

Next, call get_authorization_url. The class will automatically make a request to server_auth_url to obtain a user code for the device. The get_authorization_url method will return the URL your user must visit from another device or computer that has web browser support. The get_authorization_url method will also populate DeviceUserCode. This device user code must also be provided to the user. The user will enter the code at the URL returned by get_authorization_url.

At this time, call get_authorization. The class will begin polling the server specified in server_token_url. The polling interval is specified (in seconds) by the PollingInterval setting.

After the user has authenticated, the get_authorization method will return the authorization string. To use the authorization string with any of our components simply pass this value to the Authorization property before making the request.

Mobile Client Type

The Mobile client type is applicable to applications that are run on devices where a web browser can be used. For instance a mobile phone or tablet. The behavior when using this client type is very similar to the Application client type. The only difference between the Mobile and Application client types is the way the browser is launched, when set to Mobile the on_launch_browser event will fire but the class will not attempt to launch the browser automatically. The browser must be launched manually from code. This behavior is the only difference between the Mobile and Application client type. Please read the steps above for the Application client type for a more detailed look at the process.

JWT Bearer Token (Server to Server) Type

The JWT (JSON Web Token) Bearer Token type is available for server to server authentication. For instance this may be used by web applications to access a Google service. In this case the application will access data on behalf of the service account, not the end user. End user interaction is not required.

First, specify authorization_scope and server_token_url.

Next specify JWT specific values. The use of the JWT profile requires additional configuration settings to be specified, including a certificate with private key used to sign the JWT. Either specify the JWTJSONKey configuration setting, which will parse the necessary information automatically, or manually specify the following configuration settings:

Additional fields may be added to the JWT using the add_param method.

For example:

oauth.AuthorizationScope = "https://www.googleapis.com/auth/analytics";
oauth.ServerTokenURL =  "https://www.googleapis.com/oauth2/v3/token";
oauth.ClientProfile = OauthClientProfiles.cfJWT;
oauth.Config("JWTIssuer=111917875427-g39d5bar90mjgiuf2n5ases9qk0j2q0p@developer.gserviceaccount.com");
oauth.Config("JWTAudience=https://www.googleapis.com/oauth2/v3/token");
oauth.Config("JWTCertStoreType=2");
oauth.Config("JWTCertStore=C:\\MyCertificate.p12");
oauth.Config("JWTCertStorePassword=password");
oauth.Config("JWTCertSubject=*");
oauth.Config("JWTValidityTime=5400"); //in seconds

string authStr = oauth.GetAuthorization();

Copyright (c) 2021 /n software inc. - All rights reserved.
E-Payment Integrator 2020 Python Edition - Version 20.0 [Build 7941]