Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languageruby
titleApp Routes
linenumberstrue
#
# Let's create parameterized routes
#
# The metadata route will be fetched by the enterprise marketplaces to retrieve your configuration
route "/mno-enterprise/:marketplace_key/metadata" to "MetadataController" on action "show"
 
# The single sign-on routes will be used by enterprise marketplaces to trigger and complete SSO handshakes
route "/mno-enterprise/:marketplace_key/saml/initialize" to "SamlSsoController" on action "initialize"
route "/mno-enterprise/:marketplace_key/saml/consume" to "SamlSsoController" on action "consume"
 
# The Account Webhook routes notify you of groups being removed or users being removed from groups
route "/mno-enterprise/:marketplace_key/account/group/:id" to "AccountWebhookController" on action "destroy_group"
route "/mno-enterprise/:marketplace_key/account/group/:group_id/user/:id" to "AccountWebhookController" on action "remove_user"

# The Connec!™ webhook route will be used by enterprise marketplaces to POST data sharing notifications
route "/mno-enterpise/:marketplace_key/connec/receive" to "ConnecWebhookController" with action "receive"
 
Code Block
languageruby
titleMetadataController
linenumberstrue
# The metadata controller exposes my configuration to the requesting marketplace
# Thanks to this metadata controller, the marketplace will be able to discover my configuration
# and send webhook notifications to the right endpoint.
class MetadataController
  
	# The show action responds to the following route
	# GET /mno-enterprise/:marketplace_key/metadata
  	function show
    	# Because the URL was parameterized, we can retrieve the marketplace key
    	# from the URL parameters
    	marketplace_key = params['marketplace_key']
 
    	# Next step to make sure we authenticate the marketplace. Authentication is
    	# marketplace specific
    	unless Maestrano.with(marketplace_key).authenticate(http_basic['login'],http_basic['password'])
      		render_json("Unauthorized, code: '401')
    	end     
    
    	# Eventually, we render our configuration manifest for this specific marketplace
    	render_json(Maestrano.with(marketplace_key).to_metadata)
  	end
  
end

3.2 Single Sign-On


3.2 Single Sign-On

Info
titleOpenID also available!

The example below assumes you are using our SDK for Single Sign-On which is based on SAML 2.0.

Code Block
languageruby
titleSamlSSOController
linenumberstrue
#
# This controller handles the Single Sign-On handshake
#
class SamlSsoController
  
  	# The 'initialize' controller action responds the following route
  	# GET /mno-enterprise/:marketplace_key/saml/initialize
  	#
  	# The goal of this action is to trigger the Single Sign-On handshake
  	# between the marketplace platform and your application
  	function initialize
		# Retrieve the marketplace key from the URL parameters
    	marketplace_key = params['marketplace_key']
	
		redirect_to MaestranoSamlRequest.with(marketplace_key).new(params).redirect_url
  	end
  
  	# The 'consume' controller action responds to the following route
  	# POST /mno-enterprise/:marketplace_key/saml/consume
  	function consume
    	# Retrieve the marketplace key from the URL parameters
    	marketplace_key = params['marketplace_key']
    
		# Process the response
		saml_response = Maestrano::Saml::Response.with(marketplace_key).new(params[:SAMLResponse])
    
    	# Reject if invalid
    	unless saml_response.is_valid?
      		redirect_to "/some/error/path"
    	end
 
    	# Extract information from the response
  		user_attributes = Maestrano::SSO::BaseUser.new(marketplace_key, saml_response).to_hash_or_associative_array
  		group_attributes = Maestrano::SSO::BaseGroup.new(marketplace_key, saml_response).to_hash_or_associative_array

  		# Find/create the user and the organization
    	# The creation or retrieval of records should be scoped to a specific provider (marketplace_key)
  		user = User.find_or_create_for_maestrano_marketplace(user_attributes, marketplace_key)
  		organization = Organization.find_or_create_for_maestrano_marketplace(group_attributes, marketplace_key)

  		# Add user to the organization if not there already
  		unless organization.has_member?(user)
    		organization.add_member(user)
  		end

		# Sign the user in and redirect to application root
		# To be customised depending on how you handle user
  		# sign in and 
  		sign_user_in(user)
  		redirect_to "/some/post-login/path"
	end
 
end

...

Code Block
languageruby
titleWebhookAccountController
linenumberstrue
#
# This controller handles notification of people leaving a group (remove_user action) or companies
# cancelling their subscription to your service (destroy_group)
class WebhookAccountController
 
  	# The 'destroy_group' controller action responds the following route
  	# DESTROY /mno-enterprise/:marketplace_key/account/group/:id:id
  	function destroy_group
	    # Retrieve the request parameters
	    marketplace_key = params[:marketplace_key]
    	function destroygroup_groupuid = params[:id]


		# Authenticate request as usual
    	unless Maestrano.with(marketplace_key).authenticate(http_basic['login'],http_basic['password'])
      		render json: "Unauthorized, code: '401'
    	end
 
	    # Retrieve the request parameters
	    marketplace_key = params[:marketplace_key]
    	group_uid = params[:id]
 
	    # Retrieve the group/company
	    organization = Organization.find_by_marketplace_and_uid(marketplace_key,group_uid)
    
	    # Destroy it
	    organization.destroy
	end
  
  	# The 'destroy_group' controller action responds the following route
  	# DESTROY /mno-enterprise/:marketplace_key/account/group/:group_id/user/:id
  	function remove_user
    	
	    # Retrieve the request parameters
    	marketplace_key = params[:marketplace_key/account/group/]
	    group_uid = params[:group_id/user/:id]
	   	function removeuser_useruid = params[:id]


		# Authenticate request as usual
    	unless Maestrano.with(marketplace_key).authenticate(http_basic['login'],http_basic['password'])
	      render json: "Unauthorized, code: '401'
    	end
    
'password'])
	    # Retrieve therender request parameters
    	marketplace_key = params[:marketplace_key]
	json: "Unauthorized, code: '401'
   group_uid = params[:group_id] 	end
   user_uid = params[:id]
    
	    # Retrieve the group/company as well as the user
	    organization = Organization.find_by_marketplace_and_uid(marketplace_key,group_uid)
	    user = User.find_by_marketplace_and_uid(marketplace_key,user_uid)
 
	    # Remove the user
	    organization.remove_user(user)
	end
 
end

...

The code below shows how to bill an organization which has been tagged with a marketplace key. All  All Maestrano SDKs offer the ability to scope REST calls with a marketplace key. See the documentation of the relevant SDK for more details.

...