All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wordnik.swagger.auth.service.DefaultAuthDialog.scala Maven / Gradle / Ivy

The newest version!
package com.wordnik.swagger.auth.service

import com.wordnik.swagger.auth.model._

import org.apache.oltu.oauth2.as.issuer.{ MD5Generator, OAuthIssuerImpl }

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Date
import java.net.URLEncoder
import java.net.URI

class DefaultAuthDialog extends AuthDialog with TokenStore {
  /**
   * In this sample, the scope 'anonymous' will allow access if the redirectUri
   * is 'localhost' and provide an AnonymousTokenRequest, which is good for 3600
   * seconds
   */
  def show(clientId: String, redirectUri: String, scope: String, responseType: String, requestId: Option[String]) = {
    if(scope == "anonymous") {
      val url = "/oauth/login"

      if(redirectUri.startsWith("http://localhost")) {
        // it's good to proceed
        val oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator())
        val accessToken = oauthIssuerImpl.accessToken()
        val token = AnonymousTokenResponse(3600, accessToken)
        addAccessCode(accessToken, TokenWrapper(new Date, token))
        val redirectTo = {
          (redirectUri.indexOf("#") match {
            case i: Int if(i >= 0) => redirectUri + "&"
            case i: Int => redirectUri + "#"
          }) + "access_token=" + accessToken
        }
        ApiResponseMessage(302, redirectTo)
      }
      else throw new Exception("bad redirect_uri")
    }
    else {
      /**
       * render the login dialog
       */
      val html = 

  
    
    
    
    
    
    
  
  
    

Some Sample Appwould like to connect to your service account.

ApiResponseMessage(200, html.toString) } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy