Hub Help

Implicit Grant

Implicit grant flow ([spec|http://tools.ietf.org/html/rfc6749#section-4.2])

Prerequisites

Client is public. Typically a javascript code in a browser.

Send user to authorization server (hub)

Following code is expected to be executed in a browser.

// Get OAuth 2.0 client HubClient hubClient = HubClient.builder().baseUrl("https://sso.jetbrains.com").build(); OAuth2Client client = hubClient.getOAuthClient(); OAuth2ImplicitFlow.Builder implicitFlowBuilder = client.implicitFlow(); implicitFlowBuilder.clientId(clientServiceId); // Define landing page in client. This landing page URI should be // listed in the redirectUris property of the service associated with the client in Hub. implicitFlowBuilder.redirectUri(clientLandingPage); // Decide if login form should be shown // SKIP - if logged in - return, otherwise - force log in as guest // REQUIRED - force show login form // DEFAULT - if logged - return, otherwise - show login form implicitFlowBuilder.credentials(RequestCredentials.DEFAULT); // An id of service that will be accessed, e.g. YouTrack, TeamCity, UpSource, etc. implicitFlowBuilder.addScope(resourceServerServiceId); // Current client application state, e.g. initialliy requested URI implicitFlowBuilder.state(requestedPage); OAuth2ImplicitFlow implicitFlow = implicitFlowBuilder.build(); // Redirect user agent to authorization server response.sendRedirect(implicitFlow.getAuthUri().toASCIIString());

Javascript version

When use Ring javascript library the same code may look like

ring('auth', 'init')({ "serverUri": "https://sso.jetbrains.com", "clientId": clientServiceId, "redirectUri": clientLandingPage, "scope": resourceServerServiceId });

This code will redirect to authorization server if it is required. After authorization the same code will consume access token response from URI fragment. To get access token and pass it with resource requests use following code.

$ajax.headers['Authorization'] = function () { var accessToken = ring('auth', 'getToken')(); return 'Bearer ' + accessToken; };
Last modified: 7 May 2015