token

微信保存access_token

安稳与你 提交于 2019-12-21 12:31:07
function get_accessToken(){ $appid = '......'; $secret = '......'; $tokenFile = "./access_token.txt"; // 缓存文件名 $data = json_decode(file_get_contents($tokenFile)); //转换为json格式 if ($data->expire_time < time() or ! $data->expire_time) { //token过期的情况 $res = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret); $res = json_decode($res, true); // 对 JSON 格式的字符串进行编码 $access_token = $res['access_token']; if ($access_token) { $data->expire_time = time() + 7200; //保存2小时 $data->access_token = $access_token; $fp = fopen($tokenFile,

新浪微博 API 使用入门

こ雲淡風輕ζ 提交于 2019-12-21 11:37:14
1、注册新浪帐号 2、进行开发者认证 需要身份认证,等待了一天时间。提交身份认证后就可以使用了,不必等待认证通过。 3、创建APP 系统会为此应用分配一个APP KEY和APP SECRET,这两个字串非常重要,将会在以后认证或者信息交互时用到。 4、设置app的授权回调页 应用信息 - 高级信息 - OAuth2.0 授权设置,设置授权回调页。 如果没有自己的网站,可以把 redirecturl 设置为 https://api.weibo.com/oauth2/default.html ,程序中的 redirecturl 要与此一致。 如图: 如果没设置授权回调页地址,或者程序中的与此不一样,会出现如下错误: 访问出错了! 你所访问的站点在新浪微博的认证失败,请你联系gnocob或者稍后再试。 (error:redirect_uri_mismatch) 如图: 5、下载需要版本的 sdk http://open.weibo.com/wiki/SDK 6、查看可用 API http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3 我的应用可用的接口: http://open.weibo.com/apps/180341588/privilege 7、测试及其他 Python SDK 调用 API 测试如下: #encoding=utf-8

Generate a single use token in PHP: random_bytes or openssl_random_pseudo_bytes?

断了今生、忘了曾经 提交于 2019-12-21 07:00:24
问题 I need to generate a single-use token in PHP. There are two functions available that I can use for this that seem to do the same thing: random_bytes and openssl_random_pseudo_bytes. For example, using random_bytes : var_dump(bin2hex(random_bytes(12))); --> string(24) "338f489ec37a2c2b4943905d" and using openssl_random_pseudo_bytes : var_dump(bin2hex(openssl_random_pseudo_bytes(12))); --> string(24) "1c7febea20029bd524fba8e7" openssl_random_pseudo_bytes is PHP 5.3 and up (so I assume it's been

Android窗口与Token对应策略

拈花ヽ惹草 提交于 2019-12-21 06:56:48
概念 Android窗口分为三种类型,应用窗口,子窗口,系统窗口 每种类型窗口必须对应有一个身份标识Token,Token一般是一个binder对象 主要来看三种窗口的Token是如何分配的 addView 任何窗口的添加都会到这个方法,该方法会设置Window对应的Token,并且创建三个ArrayList,每一个Window的View,ViewRootImpl,LayoutParams会一一对应 /frameworks/base/core/java/android/view/WindowManagerGlobal.java public void addView ( View view , ViewGroup . LayoutParams params , Display display , Window parentWindow ) { . . . . . . final WindowManager . LayoutParams wparams = ( WindowManager . LayoutParams ) params ; if ( parentWindow != null ) { //此方法会设置不同窗口的Token parentWindow . adjustLayoutParamsForSubWindow ( wparams ) ; } else { . . .

Extend auth token without refreshing the page

霸气de小男生 提交于 2019-12-21 06:02:11
问题 Users want to use my facebook app for many hours without refreshing the browser. But token expires in 2 hours. Now I ask users to refresh the page but that's annoying. I don't want to ask offline access permissions because it will scare some users. The best solution will be somehow "relogin" and get new token without refreshing the page. Is it possible? 回答1: I would subscribe to the expiry trigger (I think this is authResponseChange), then automate another login check. It won't be a perfect

HttpClientUtils — 模拟http-https请求工具类

不打扰是莪最后的温柔 提交于 2019-12-21 03:43:54
HttpClientUtils — 模拟http-https请求工具类 import org . apache . http . NameValuePair ; import org . apache . http . client . entity . UrlEncodedFormEntity ; import org . apache . http . client . methods . CloseableHttpResponse ; import org . apache . http . client . methods . HttpGet ; import org . apache . http . client . methods . HttpPost ; import org . apache . http . client . utils . URIBuilder ; import org . apache . http . entity . ContentType ; import org . apache . http . entity . StringEntity ; import org . apache . http . impl . client . CloseableHttpClient ; import org . apache . http .

How to authenticate a user in websocket connection in django channels when using token authentication [duplicate]

混江龙づ霸主 提交于 2019-12-21 02:55:21
问题 This question already has answers here : How do you authenticate a websocket with token authentication on django channels? (5 answers) Closed 7 months ago . I am using a frontend framework (Vuejs) and django-rest-framework for the REST API in my project. Also, for JSON web token authentication I am using django-rest-framework-jwt. After a successful login, the user is provided with a token. This token is passed into every request to fetch any API related stuff. Now I would like to integrate

Implementing a token authentication

末鹿安然 提交于 2019-12-21 02:40:36
问题 Which are the steps must I follow to implement a token authentication in my web page? Any summary or links will be appreciated. I want to implement similar to Facebook or Google, first time client loggin and receive token and then use it in next actions. I read also about OAuth but I don't want to give access to my application from 3rd party. Thanks for the long response and it seems clear to me I need to read more about this. What I want is to know the "steps" to implement a basic web

JSON Web Token 入门教程

巧了我就是萌 提交于 2019-12-20 20:47:12
作者: 阮一峰 日期: 2018年7月23日 JSON Web Token(缩写 JWT)是目前最流行的跨域认证解决方案,本文介绍它的原理和用法。 一、跨域认证的问题 互联网服务离不开用户认证。一般流程是下面这样。 1、用户向服务器发送用户名和密码。 2、服务器验证通过后,在当前对话(session)里面保存相关数据,比如用户角色、登录时间等等。 3、服务器向用户返回一个 session_id,写入用户的 Cookie。 4、用户随后的每一次请求,都会通过 Cookie,将 session_id 传回服务器。 5、服务器收到 session_id,找到前期保存的数据,由此得知用户的身份。 这种模式的问题在于,扩展性(scaling)不好。单机当然没有问题,如果是服务器集群,或者是跨域的服务导向架构,就要求 session 数据共享,每台服务器都能够读取 session。 举例来说,A 网站和 B 网站是同一家公司的关联服务。现在要求,用户只要在其中一个网站登录,再访问另一个网站就会自动登录,请问怎么实现? 一种解决方案是 session 数据持久化,写入数据库或别的持久层。各种服务收到请求后,都向持久层请求数据。这种方案的优点是架构清晰,缺点是工程量比较大。另外,持久层万一挂了,就会单点失败。 另一种方案是服务器索性不保存 session 数据了,所有数据都保存在客户端

认证方案之初步认识JWT

拥有回忆 提交于 2019-12-20 20:44:57
前言 : 现在越来越多的项目或多或少会用到JWT,为什么会出现使用JWT这样的场景的呢? 假设现在有一个APP,后台是分布式系统。APP的首页模块部署在上海机房的服务器上,子页面模块部署在深圳机房的服务器上。此时你从首页登录了该APP,然后跳转到子页面模块。session在两个机房之间不能同步,用户是否需要重新登录? 传统的方式(cookie+session)需要重新登录,用户体验不好。session共享(在多台物理机之间传输和复制session)方式对网络IO的压力大,延迟太长,用户体验也不好。 说到这大家可能会想到,用服务器的session_id存储到cookies中也能做到,为什么非要用token呢?网上有许多文章来比较token和session的优缺点,其实,开发web应用的话用哪种都行。但如果是开发api接口,前后端分离,最好使用token,为什么这么说呢,因为session+cookies是基于web的。但是针对 api接口,可能会考虑到移动端,app是没有cookies和session的。 Session方式存储用户信息的最大问题在于要占用大量服务器内存,增加服务器的开销。 而JWT方式将用户状态分散到了客户端中,可以明显减轻服务端的内存压力。Session的状态是存储在服务器端,客户端只有session id;而Token的状态是存储在客户端 原理 : JSON