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

com.garmin.controller.OAuthController Maven / Gradle / Ivy

The newest version!
package com.garmin.controller;

import com.garmin.service.OAuthService;
import com.garmin.vo.ResponseToken;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
/**
 * @Classname OAuthController
 * @Description Garmin Authorized Controller
 * @Date 2019/10/24 10:27
 * @Created by weihua.zou
 */
@Controller
@RequestMapping(value ="/garmin")
public class OAuthController{
    private final OAuthService oAuthService;

    public OAuthController(OAuthService oAuthService) {
        this.oAuthService = oAuthService;
    }


    /**
     * Authorization interface, the parameter is the username
     * @param account
     * @return
     */
    @RequestMapping("/oauth/{sid}")
    public ResponseEntity oauth(@PathVariable String sid){
        try {
            return oAuthService.oauth(sid);
        }catch (Exception e){
            return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
        }

    }

    /**
     *Authorize the callback interface. If the authorization succeeds,
     * it will return oauthToken and oauthVerifierValue.
     * If the authorization fails, oauthVerifierValue is null.
     * @param oauthToken
     * @param oauthVerifierValue
     * @return
     */
    @RequestMapping("/accessToken")
    @ResponseBody
    ResponseEntity oauthAccessToken(@RequestParam(value = "oauth_token") String oauthToken,
                                   @RequestParam(value = "oauth_verifier") String oauthVerifierValue){
        try {
            return oAuthService.getUserAccessTokenAndSecret(oauthToken,oauthVerifierValue);
        }catch (Exception e){
            return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
        }

    }



}