Skip to content

Get Authorization URL

Description

This API is used to obtain a URL for the login providers authorization (login) form. The API is used in the OAuth login approach without using login provider's SDK (see Step 1 in Login Without Provider's SDK).

Method

// Login externally authenticated user. The method exchanges the OAuth token (accessToken) to BackendlessUser object. 
// Notice the method is non-blocking - the return value arrives through the AsyncCallback object.
public void Backendless.UserService.getAuthorizationUrlLink( String authProviderCode, 
                                     Map<String, String> fieldsMappings,
                                     List<String> scope,
                                     AsyncCallback<String> responder ) throws BackendlessException

public void Backendless.UserService.getAuthorizationUrlLink( String authProviderCode,
                                     String callbackUrlDomain,
                                     Map<String, String> fieldsMappings,
                                     List<String> scope,
                                     AsyncCallback<String> responder ) throws BackendlessException

where:

Argument                Description
providerCode Name of the login provider as displayed in Backendless Console - see the specific provider screen at Users > Login Providers. String value.
fieldsMappings Optional parameter. A mapping of user properties between OAuth provider and Backendless. If the map object is not null, it should contain a mapping between the provider specific property names and the column names in the Users table. Consider the following mappings:
"my_email" >> "email"
"my_name" >> "name"
The key identifies the provider's property name and the value is the name of the mapped property (column name) in Backendless. In the example above, "my_email" and "my_name" are the properties returned by the OAuth2 provider and the corresponding values will be respectively stored in the "email" and "name" columns in Backendless. Must be an object.
scope Optional parameter. A collection of security scopes the client application is requesting the permissions for. String value.
responder Optional parameter. A responder object containing success/failure methods which are called when the user is logged in or if an error occurs. If the operation is successful, the callback method provides the BackendlessUser argument representing the currently logged in user.
callbackUrlDomain Optional Parameter. Allows customizing the callback URL which is used during the authorization process. By default, if the value for this parameter is not provided or set to null, the server will return the provider's authorization URL. However, when you provide a valid value for this parameter, the server will generate the URL with a callback that utilizes the specified domain. This feature allows you to tailor the callback URL according to your specific needs and enhance the authorization process for your application. String value.

Return Value

The method returns an authorization URL. It should be used to open up the provider's login form.

The object in the response has the following structure:

{          
  "url": "authorization URL"  
}

Example

The example below retrieves the authorization URL for "facebook".

// Login externally authenticated user. The method exchanges the OAuth token (accessToken) to BackendlessUser object. 
// Notice the method is non-blocking - the return value arrives through the AsyncCallback object.
    String authProviderCode = "<facebook>";
    Map<String, String> fieldsMappings = new HashMap<>();
    List<String> scope = new ArrayList<>();

    Backendless.UserService.getAuthorizationUrlLink( authProviderCode, fieldsMappings, scope, new AsyncCallback<String>()
    {
      @Override
      public void handleResponse( String s )
      {
        // result handling logic
      }

      @Override
      public void handleFault( BackendlessFault backendlessFault )
      {
        // error handling logic
      }
    } );


    String authProviderCode = "facebook";
    String callbackUrlDomain = "<callbackUrlDomain>";
    Map<String, String> fieldsMappings = new HashMap<>();
    List<String> scope = new ArrayList<>();

    Backendless.UserService.getAuthorizationUrlLink( authProviderCode, callbackUrlDomain, fieldsMappings, scope, new AsyncCallback<String>()
    {
      @Override
      public void handleResponse( String s )
      {
        // result handling logic
      }

      @Override
      public void handleFault( BackendlessFault backendlessFault )
      {
        // error handling logic
      }
    } );